void LCD_FSMCConf(void) { FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef p; RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); p.FSMC_AddressSetupTime = 5; p.FSMC_AddressHoldTime = 0; p.FSMC_DataSetupTime = 9; p.FSMC_BusTurnAroundDuration = 0; p.FSMC_CLKDivision = 0; p.FSMC_DataLatency = 0; p.FSMC_AccessMode = FSMC_AccessMode_A; FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; 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); FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); }
//---------------------------------------------------------------------------- void RCC_Configuration(void) { unsigned int startDelay; RCC_DeInit(); //-- RCC system reset(for debug purpose) RCC_HSICmd(ENABLE); RCC_HSEConfig(RCC_HSE_OFF); // delay_40ms startDelay = 960000; while (startDelay) startDelay--; //-- Enable Prefetch Buffer FLASH_PrefetchBufferCmd(ENABLE); FLASH_SetLatency(FLASH_Latency_3); //-- Flash 3 wait state for 120MHz //-- PLLCLK = 16MHz/16 * 240/2 = 120 MHz RCC_PLLCmd(DISABLE); RCC_HCLKConfig (RCC_SYSCLK_Div1 ) ; RCC_PCLK1Config ( RCC_HCLK_Div4) ; RCC_PCLK2Config ( RCC_HCLK_Div2) ; RCC_PLLConfig(RCC_PLLSource_HSI, TPLL_M, TPLL_N, TPLL_P, TPLL_Q); // // //-- Enable PLL & wait till PLL is ready RCC_PLLCmd(ENABLE); while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); // startDelay = 240000; // while (startDelay) startDelay--; // //-- Select PLL as system clock source & wait till PLL is used // //-- as system clock source startDelay = 10000; while (startDelay) startDelay--; RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // while(RCC_GetSYSCLKSource() != 0x08); // // RCC_ADCCLKConfig(RCC_PCLK2_Div4); startDelay = RCC_GetSYSCLKSource() ; /* DMA clock enable */ RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_DMA1 | RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_BKPSRAM, ENABLE); /* Enable USART2 clock */ // uart4 rs-485, uart6 irps RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART3 | RCC_APB1Periph_UART4 | RCC_APB1Periph_PWR | RCC_APB1Periph_TIM2, ENABLE); /* Enable USART1, GPIOA, GPIOx and AFIO clocks */ RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 | RCC_APB2Periph_USART1 , ENABLE); RCC_AHB3PeriphClockCmd ( RCC_AHB3Periph_FSMC , ENABLE); }
void ILI9341::fsmcSetup() { FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef FSMC_NORSRAMTimingInitStructureRead; FSMC_NORSRAMTimingInitTypeDef FSMC_NORSRAMTimingInitStructureWrite; /* Enable FSMC Clock */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); /* Define Read timing parameters */ FSMC_NORSRAMTimingInitStructureRead.FSMC_AddressSetupTime = 1; FSMC_NORSRAMTimingInitStructureRead.FSMC_AddressHoldTime = 0; FSMC_NORSRAMTimingInitStructureRead.FSMC_DataSetupTime = 15; FSMC_NORSRAMTimingInitStructureRead.FSMC_BusTurnAroundDuration = 0; FSMC_NORSRAMTimingInitStructureRead.FSMC_CLKDivision = 1; FSMC_NORSRAMTimingInitStructureRead.FSMC_DataLatency = 0; FSMC_NORSRAMTimingInitStructureRead.FSMC_AccessMode = FSMC_AccessMode_A; /* Define Write Timing parameters */ FSMC_NORSRAMTimingInitStructureWrite.FSMC_AddressSetupTime = 2; // 2 FSMC_NORSRAMTimingInitStructureWrite.FSMC_AddressHoldTime = 0; // 0 FSMC_NORSRAMTimingInitStructureWrite.FSMC_DataSetupTime = 5; // 5 FSMC_NORSRAMTimingInitStructureWrite.FSMC_BusTurnAroundDuration = 0; FSMC_NORSRAMTimingInitStructureWrite.FSMC_CLKDivision = 1; FSMC_NORSRAMTimingInitStructureWrite.FSMC_DataLatency = 0; FSMC_NORSRAMTimingInitStructureWrite.FSMC_AccessMode = FSMC_AccessMode_A; /* Define protocol type */ FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; //Bank1 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //No mux FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; //SRAM type FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; //16 bits wide FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; //No Burst FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; // No wait FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; //Don'tcare FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; //No wrap mode FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; //Don't care FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; //Don't care FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Enable; //Allow distinct Read/Write parameters FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; //Don't care // Set read timing structure FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &FSMC_NORSRAMTimingInitStructureRead; // Set write timing structure FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &FSMC_NORSRAMTimingInitStructureWrite; // Initialize FSMC for read and write FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); // Enable FSMC FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); }
void platform_init_memory( void ) { /* Enable FSMC clock */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); /* Set the bus data width */ *( sram_control_registers.bcr ) &= ( uint32_t )( ~( 0x03 << MWID_START ) ); *( sram_control_registers.bcr ) |= ( uint32_t )( 1 << MWID_START ); /* Enable writes on this memory device */ *(sram_control_registers.bcr) |= ( uint32_t )( 1 << WREN_START ); /* Clear address data muxing */ *(sram_control_registers.bcr) &= ( uint32_t )( ~( 1 << MUXEN_START ) ); f4_sram_timings_init( &IS66WVE4M16BLL, &IS66WVE4M16BLL_settings ); f4_sram_pins_init( &IS66WVE4M16BLL, &IS66WVE4M16BLL_settings ); /* enable this memory bank, nor a chip select( for every memory bank we can have 4 chip selects ) */ /* But still remember that they are all shared between all 4 banks. Once used for one of the banks */ /* chip select can not be used again */ *(sram_control_registers.bcr) |= ( 1 << MBKEN_START ); return; }
void __USER_TEXT sdram_init(void) { struct fmc_sdram_timing_cfg fs_timing_init; struct fmc_sdram_cfg fs_init; sdram_gpio_init(); RCC_AHB3PeriphClockCmd(RCC_AHB3ENR_FMCEN, 1); fs_timing_init.lta_delay = 2; /* 2 clock cycles */ fs_timing_init.esr_delay = 7; /* 70ns */ fs_timing_init.sr_time = 4; /* 42ns */ fs_timing_init.rc_delay = 7; /* 70 */ fs_timing_init.wr_time = 2; /* 1+ 7ns */ fs_timing_init.rp_delay = 2; /* 20ns */ fs_timing_init.rcd_delay = 2; /* 20ns */ fs_init.bank = FMC_Bank2_SDRAM; fs_init.column_bits_number = FMC_ColumnBits_Number_8b; fs_init.row_bits_number = FMC_RowBits_Number_12b; fs_init.sdmemory_data_width = SDRAM_MEMORY_WIDTH; fs_init.internal_bank_number = FMC_InternalBank_Number_4; fs_init.cas_latency = SDRAM_CAS_LATENCY; fs_init.write_protection = FMC_Write_Protection_Disable; fs_init.sd_clock_period = SDCLOCK_PERIOD; fs_init.readburst = SDRAM_READBURST; fs_init.readpipe_delay = FMC_ReadPipe_Delay_1; fs_init.timing = &fs_timing_init; fmc_sdram_config(&fs_init); sdram_init_seq(); }
/** * @brief 初始化配置使用SDRAM的FMC及GPIO接口, * 本函数在SDRAM读写操作前需要被调用 * @param None * @retval None */ void SDRAM_Init(void) { FMC_SDRAMInitTypeDef FMC_SDRAMInitStructure; FMC_SDRAMTimingInitTypeDef FMC_SDRAMTimingInitStructure; /* 配置FMC接口相关的 GPIO*/ SDRAM_GPIO_Config(); /* 使能 FMC 时钟 */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE); /* SDRAM时序结构体,根据SDRAM参数表配置----------------*/ /* SDCLK: 90 Mhz (HCLK/2 :180Mhz/2) 1个时钟周期Tsdclk =1/90MHz=11.11ns*/ /* TMRD: 2 Clock cycles */ FMC_SDRAMTimingInitStructure.FMC_LoadToActiveDelay = 2; /* TXSR: min=70ns (7x11.11ns) */ FMC_SDRAMTimingInitStructure.FMC_ExitSelfRefreshDelay = 7; /* TRAS: min=42ns (4x11.11ns) max=120k (ns) */ FMC_SDRAMTimingInitStructure.FMC_SelfRefreshTime = 4; /* TRC: min=70 (7x11.11ns) */ FMC_SDRAMTimingInitStructure.FMC_RowCycleDelay = 7; /* TWR: min=1+ 7ns (1+1x11.11ns) */ FMC_SDRAMTimingInitStructure.FMC_WriteRecoveryTime = 2; /* TRP: 15ns => 2x11.11ns */ FMC_SDRAMTimingInitStructure.FMC_RPDelay = 2; /* TRCD: 15ns => 2x11.11ns */ FMC_SDRAMTimingInitStructure.FMC_RCDDelay = 2; /* FMC SDRAM 控制配置 */ /*选择存储区域*/ FMC_SDRAMInitStructure.FMC_Bank = FMC_BANK_SDRAM; /* 行地址线宽度: [7:0] */ FMC_SDRAMInitStructure.FMC_ColumnBitsNumber = FMC_ColumnBits_Number_8b; /* 列地址线宽度: [11:0] */ FMC_SDRAMInitStructure.FMC_RowBitsNumber = FMC_RowBits_Number_12b; /* 数据线宽度 */ FMC_SDRAMInitStructure.FMC_SDMemoryDataWidth = SDRAM_MEMORY_WIDTH; /* SDRAM内部bank数量*/ FMC_SDRAMInitStructure.FMC_InternalBankNumber = FMC_InternalBank_Number_4; /* CAS潜伏期 */ FMC_SDRAMInitStructure.FMC_CASLatency = SDRAM_CAS_LATENCY; /* 禁止写保护*/ FMC_SDRAMInitStructure.FMC_WriteProtection = FMC_Write_Protection_Disable; /* SDCLK时钟分频因子,SDCLK = HCLK/SDCLOCK_PERIOD*/ FMC_SDRAMInitStructure.FMC_SDClockPeriod = SDCLOCK_PERIOD; /* 突发读模式设置*/ FMC_SDRAMInitStructure.FMC_ReadBurst = SDRAM_READBURST; /* 读延迟配置 */ FMC_SDRAMInitStructure.FMC_ReadPipeDelay = FMC_ReadPipe_Delay_0; /* SDRAM时序参数 */ FMC_SDRAMInitStructure.FMC_SDRAMTimingStruct = &FMC_SDRAMTimingInitStructure; /* 调用初始化函数,向寄存器写入配置 */ FMC_SDRAMInit(&FMC_SDRAMInitStructure); /* 执行FMC SDRAM的初始化流程*/ SDRAM_InitSequence(); }
/** * @brief Initialize FMC module for SDRAM memory. * @param None. * @retval None. */ static void SDRAM_FMCInit(void) { FMC_SDRAMInitTypeDef FMC_SDRAMInitStructure = { 0 }; FMC_SDRAMTimingInitTypeDef FMC_SDRAMTimingInitStructure = { 0 }; /* Enable FMC clock */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE); /* FMC Configuration. */ /* FMC SDRAM Bank configuration */ /* Timing configuration for 90 Mhz of SD clock frequency (180Mhz/2) */ /* TMRD: 2 Clock cycles */ FMC_SDRAMTimingInitStructure.FMC_LoadToActiveDelay = 2; /* TXSR: min=70ns (7x11.11ns) */ FMC_SDRAMTimingInitStructure.FMC_ExitSelfRefreshDelay = 7; /* TRAS: min=42ns (4x11.11ns) max=120k (ns) */ FMC_SDRAMTimingInitStructure.FMC_SelfRefreshTime = 4; /* TRC: min=70 (7x11.11ns) */ FMC_SDRAMTimingInitStructure.FMC_RowCycleDelay = 7; /* TWR: min=1+ 7ns (1+1x11.11ns) */ FMC_SDRAMTimingInitStructure.FMC_WriteRecoveryTime = 2; /* TRP: 20ns => 2x11.11ns */ FMC_SDRAMTimingInitStructure.FMC_RPDelay = 2; /* TRCD: 20ns => 2x11.11ns */ FMC_SDRAMTimingInitStructure.FMC_RCDDelay = 2; /* FMC SDRAM control configuration. */ FMC_SDRAMInitStructure.FMC_Bank = FMC_Bank2_SDRAM; /* Row addressing: [7:0] */ FMC_SDRAMInitStructure.FMC_ColumnBitsNumber = FMC_ColumnBits_Number_8b; /* Column addressing: [11:0] */ FMC_SDRAMInitStructure.FMC_RowBitsNumber = FMC_RowBits_Number_12b; FMC_SDRAMInitStructure.FMC_SDMemoryDataWidth = SDRAM_MEMORY_WIDTH; FMC_SDRAMInitStructure.FMC_InternalBankNumber = FMC_InternalBank_Number_4; FMC_SDRAMInitStructure.FMC_CASLatency = SDRAM_CAS_LATENCY; FMC_SDRAMInitStructure.FMC_WriteProtection = FMC_Write_Protection_Disable; FMC_SDRAMInitStructure.FMC_SDClockPeriod = SDCLOCK_PERIOD; FMC_SDRAMInitStructure.FMC_ReadBurst = SDRAM_READBURST; FMC_SDRAMInitStructure.FMC_ReadPipeDelay = FMC_ReadPipe_Delay_1; FMC_SDRAMInitStructure.FMC_SDRAMTimingStruct = &FMC_SDRAMTimingInitStructure; /* FMC SDRAM bank initialization. */ FMC_SDRAMInit(&FMC_SDRAMInitStructure); }
static void lcd_line_init(void){ GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOG, ENABLE); RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); 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_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_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOE, GPIO_PinSource2 , 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_2 | 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_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOG, GPIO_PinSource5 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource12 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource13 , GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_13 | GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOG, &GPIO_InitStructure); }
void LCD_CtrlLinesConfig(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF, ENABLE); RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC); // D2 GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC); // D3 GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC); // NOE -> RD GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC); // NWE -> WR GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, GPIO_AF_FSMC); // NE1 -> CS GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FSMC); // D13 GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FSMC); // D14 GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FSMC); // D15 GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC); // A16 -> RS GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC); // D0 GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC); // D1 GPIO_PinAFConfig(GPIOE, GPIO_PinSource7, GPIO_AF_FSMC); // D4 GPIO_PinAFConfig(GPIOE, GPIO_PinSource8, GPIO_AF_FSMC); // D5 GPIO_PinAFConfig(GPIOE, GPIO_PinSource9, GPIO_AF_FSMC); // D6 GPIO_PinAFConfig(GPIOE, GPIO_PinSource10, GPIO_AF_FSMC); // D7 GPIO_PinAFConfig(GPIOE, GPIO_PinSource11, GPIO_AF_FSMC); // D8 GPIO_PinAFConfig(GPIOE, GPIO_PinSource12, GPIO_AF_FSMC); // D9 GPIO_PinAFConfig(GPIOE, GPIO_PinSource13, GPIO_AF_FSMC); // D10 GPIO_PinAFConfig(GPIOE, GPIO_PinSource14, GPIO_AF_FSMC); // D11 GPIO_PinAFConfig(GPIOE, GPIO_PinSource15, GPIO_AF_FSMC); // D12 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | 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); GPIO_InitStructure.GPIO_Pin = 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_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(GPIOE, &GPIO_InitStructure); }
/** * @brief Configures the FMC and GPIOs to interface with the NOR flash memory. * This function must be called before any read/write operation * on the NOR flash. * @param None * @retval None */ void NOR_Init(void) { FMC_NORSRAMInitTypeDef FMC_NORSRAMInitStructure; FMC_NORSRAMTimingInitTypeDef FMC_NORSRAMTimingStructure; /* GPIO configuration for FMC NOR bank */ NOR_GPIOConfig(); /* Enable FMC Clock */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE); /* FMC Configuration ---------------------------------------------------------*/ /* NOR memory timing configuration */ FMC_NORSRAMTimingStructure.FMC_AddressSetupTime = 4; FMC_NORSRAMTimingStructure.FMC_AddressHoldTime = 3; FMC_NORSRAMTimingStructure.FMC_DataSetupTime = 7; FMC_NORSRAMTimingStructure.FMC_BusTurnAroundDuration = 1; FMC_NORSRAMTimingStructure.FMC_CLKDivision = 1; FMC_NORSRAMTimingStructure.FMC_DataLatency = 0; FMC_NORSRAMTimingStructure.FMC_AccessMode = FMC_AccessMode_A; /* NOR memory control configuration */ FMC_NORSRAMInitStructure.FMC_Bank = FMC_Bank1_NORSRAM1; FMC_NORSRAMInitStructure.FMC_DataAddressMux = FMC_DataAddressMux_Disable; FMC_NORSRAMInitStructure.FMC_MemoryType = FMC_MemoryType_NOR; FMC_NORSRAMInitStructure.FMC_MemoryDataWidth = FMC_NORSRAM_MemoryDataWidth_16b; FMC_NORSRAMInitStructure.FMC_BurstAccessMode = NOR_BURSTACCESS; FMC_NORSRAMInitStructure.FMC_WaitSignalPolarity = FMC_WaitSignalPolarity_Low; FMC_NORSRAMInitStructure.FMC_WrapMode = FMC_WrapMode_Disable; FMC_NORSRAMInitStructure.FMC_WaitSignalActive = FMC_WaitSignalActive_BeforeWaitState; FMC_NORSRAMInitStructure.FMC_WriteOperation = FMC_WriteOperation_Enable; FMC_NORSRAMInitStructure.FMC_WaitSignal = FMC_WaitSignal_Disable; FMC_NORSRAMInitStructure.FMC_ExtendedMode = FMC_ExtendedMode_Disable; FMC_NORSRAMInitStructure.FMC_AsynchronousWait = FMC_AsynchronousWait_Disable; FMC_NORSRAMInitStructure.FMC_WriteBurst = NOR_WRITEBURST; FMC_NORSRAMInitStructure.FMC_ContinousClock = CONTINUOUSCLOCK_FEATURE; FMC_NORSRAMInitStructure.FMC_ReadWriteTimingStruct = &FMC_NORSRAMTimingStructure; FMC_NORSRAMInitStructure.FMC_WriteTimingStruct = &FMC_NORSRAMTimingStructure; /* FMC NOR memory de-initializtion */ FMC_NORSRAMDeInit(FMC_Bank1_NORSRAM1); /* FMC NOR bank initialization */ FMC_NORSRAMInit(&FMC_NORSRAMInitStructure); /* Enable the NOR memory bank */ FMC_NORSRAMCmd(FMC_Bank1_NORSRAM1, ENABLE); }
//*---------------------------------------------------------------------------- //* Function Name : UiLcdHy28_FSMCConfig //* Object : //* Input Parameters : //* Output Parameters : //* Functions called : //*---------------------------------------------------------------------------- void UiLcdHy28_FSMCConfig(void) { FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef p; // Enable FSMC clock RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); //-- FSMC Configuration ------------------------------------------------------ //----------------------- SRAM Bank 3 ---------------------------------------- // FSMC_Bank1_NORSRAM4 configuration p.FSMC_AddressSetupTime = 3; p.FSMC_AddressHoldTime = 0; p.FSMC_DataSetupTime = 9; p.FSMC_BusTurnAroundDuration = 0; p.FSMC_CLKDivision = 0; p.FSMC_DataLatency = 0; p.FSMC_AccessMode = FSMC_AccessMode_A; // Color LCD configuration ------------------------------------ // LCD configured as follow: // - Data/Address MUX = Disable // - Memory Type = SRAM // - Data Width = 16bit // - Write Operation = Enable // - Extended Mode = Enable // - Asynchronous Wait = Disable FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; 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); FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); }
/** * @brief Configures the Parallel interface (FSMC) for LCD(Parallel mode) * @param None * @retval None */ static void FSMC_Configuration(void) { FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef p; /* Enable FSMC clock */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); /* FSMC_Bank1_NORSRAM1 configuration */ p.FSMC_AddressSetupTime = 3; p.FSMC_AddressHoldTime = 0; p.FSMC_DataSetupTime = 4; p.FSMC_BusTurnAroundDuration = 0; p.FSMC_CLKDivision = 0; p.FSMC_DataLatency = 0; p.FSMC_AccessMode = FSMC_AccessMode_B; /* Color LCD configuration ------------------------------------ LCD configured as follow: - Data/Address MUX = Disable - Memory Type = SRAM - Data Width = 16bit - Write Operation = Enable - Extended Mode = Enable - Asynchronous Wait = Disable */ FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; 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 NOR/SRAM Bank1 */ FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); }
/** * @brief Configures the FMC and GPIOs to interface with the SRAM memory. * This function must be called before any write/read operation * on the SRAM. * @param None * @retval None */ void SRAM_Init(void) { FMC_NORSRAMInitTypeDef FMC_NORSRAMInitStructure; FMC_NORSRAMTimingInitTypeDef NORSRAMTimingStructure; /* GPIO configuration for FMC SRAM bank */ SRAM_GPIOConfig(); /* Enable FMC clock */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE); /* FMC Configuration ---------------------------------------------------------*/ /* SRAM Timing configuration */ NORSRAMTimingStructure.FMC_AddressSetupTime = 2; NORSRAMTimingStructure.FMC_AddressHoldTime = 1; NORSRAMTimingStructure.FMC_DataSetupTime = 2; NORSRAMTimingStructure.FMC_BusTurnAroundDuration = 1; NORSRAMTimingStructure.FMC_CLKDivision = 1; NORSRAMTimingStructure.FMC_DataLatency = 0; NORSRAMTimingStructure.FMC_AccessMode = FMC_AccessMode_A; /* FMC SRAM control configuration */ FMC_NORSRAMInitStructure.FMC_Bank = FMC_Bank1_NORSRAM2; FMC_NORSRAMInitStructure.FMC_DataAddressMux = FMC_DataAddressMux_Disable; FMC_NORSRAMInitStructure.FMC_MemoryType = FMC_MemoryType_SRAM; FMC_NORSRAMInitStructure.FMC_MemoryDataWidth = SRAM_MEMORY_WIDTH; FMC_NORSRAMInitStructure.FMC_BurstAccessMode = SRAM_BURSTACCESS; FMC_NORSRAMInitStructure.FMC_AsynchronousWait = FMC_AsynchronousWait_Disable; FMC_NORSRAMInitStructure.FMC_WaitSignalPolarity = FMC_WaitSignalPolarity_Low; FMC_NORSRAMInitStructure.FMC_WrapMode = FMC_WrapMode_Disable; FMC_NORSRAMInitStructure.FMC_WaitSignalActive = FMC_WaitSignalActive_BeforeWaitState; FMC_NORSRAMInitStructure.FMC_WriteOperation = FMC_WriteOperation_Enable; FMC_NORSRAMInitStructure.FMC_WaitSignal = FMC_WaitSignal_Disable; FMC_NORSRAMInitStructure.FMC_ExtendedMode = FMC_ExtendedMode_Disable; FMC_NORSRAMInitStructure.FMC_WriteBurst = SRAM_WRITEBURST; FMC_NORSRAMInitStructure.FMC_ContinousClock = CONTINUOUSCLOCK_FEATURE; FMC_NORSRAMInitStructure.FMC_ReadWriteTimingStruct = &NORSRAMTimingStructure; FMC_NORSRAMInitStructure.FMC_WriteTimingStruct = &NORSRAMTimingStructure; /* SRAM configuration */ FMC_NORSRAMInit(&FMC_NORSRAMInitStructure); /* Enable FMC Bank1_SRAM2 Bank */ FMC_NORSRAMCmd(FMC_Bank1_NORSRAM2, ENABLE); }
void initFSMC() { // FSMC and TFTLCD fsmcData =(uint16_t*) 0x60020000; // sets a16 fsmcRegister =(uint16_t*) 0x60000000; // clears a16 FSMC_NORSRAMTimingInitTypeDef timing;//={0}; FSMC_NORSRAMInitTypeDef init;//={0}; RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE); timing.FSMC_AddressSetupTime=2; // want 2 : timing.FSMC_DataSetupTime=5; // keep timing.FSMC_AccessMode=FSMC_AccessMode_B/*FSMC_AccessMode_A*/; // B? This is how he does it in ili9325 timing.FSMC_CLKDivision=1; // ? timing.FSMC_DataLatency=0; timing.FSMC_BusTurnAroundDuration=0; timing.FSMC_AddressHoldTime=0; // itiming.nitialise how the FSMC will work and then enable it init.FSMC_Bank=FSMC_Bank1_NORSRAM1; // keep init.FSMC_DataAddressMux=FSMC_DataAddressMux_Disable; // keep init.FSMC_MemoryType=FSMC_MemoryType_SRAM; // keep init.FSMC_MemoryDataWidth=FSMC_MemoryDataWidth_16b; // make 8 bit? init.FSMC_BurstAccessMode=FSMC_BurstAccessMode_Disable; // keep init.FSMC_WaitSignalPolarity=FSMC_WaitSignalPolarity_Low; // keep init.FSMC_WrapMode=FSMC_WrapMode_Disable; // keep init.FSMC_WaitSignalActive=FSMC_WaitSignalActive_BeforeWaitState; // keep init.FSMC_WriteOperation=FSMC_WriteOperation_Enable; // keep init.FSMC_WaitSignal=FSMC_WaitSignal_Disable; // keep init.FSMC_ExtendedMode=FSMC_ExtendedMode_Disable; // keep init.FSMC_WriteBurst=FSMC_WriteBurst_Disable; // keep init.FSMC_ReadWriteTimingStruct=&timing; init.FSMC_WriteTimingStruct=&timing; init.FSMC_AsynchronousWait=FSMC_AsynchronousWait_Disable; // keep FSMC_NORSRAMInit(&init); FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1,ENABLE); }
void init_GPIO_RCC(void) { #if defined(STM32F10X_MD) || defined(STM32F10X_HD) RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE); #else RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOA, ENABLE); RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); #endif #ifdef STM32F10X_MD RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); #endif #ifdef STM32F10X_HD RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); #if USE_FSMC RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE); #endif #endif }
int RCCSetClock(const void* pPeriph, const uint32_t nClockId, const FunctionalState NewState) { uint32_t nPeriph = (uint32_t)pPeriph; if(nPeriph >= APB1PERIPH_BASE && nPeriph < APB2PERIPH_BASE ){ RCC_APB1PeriphClockCmd(nClockId,NewState); }else if(nPeriph >= APB2PERIPH_BASE && nPeriph <= AHB1PERIPH_BASE){ RCC_APB2PeriphClockCmd(nClockId,NewState); }else if(nPeriph >= AHB1PERIPH_BASE && nPeriph <= AHB2PERIPH_BASE){ RCC_AHB1PeriphClockCmd(nClockId,NewState); }else if(nPeriph >= AHB2PERIPH_BASE){ RCC_AHB2PeriphClockCmd(nClockId,NewState); }else if(nClockId == RCC_AHB3Periph_FSMC){ RCC_AHB3PeriphClockCmd(nClockId,NewState); } int b=0; for(int ii=0;ii<10;ii++) b++; return(b); }
//-------------------------------------------------------------- // interne Funktion // Init vom FMC fuer das SDRAM //-------------------------------------------------------------- void P_SDRAM_InitFMC(void) { FMC_SDRAMInitTypeDef FMC_SDRAMInitStructure; FMC_SDRAMTimingInitTypeDef FMC_SDRAMTimingInitStructure; RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE); //--------------------------------------------------------- // FMC auf 180MHz/2 = 90MHz einstellen // 90MHz = 11,11 ns // Alle Timings laut Datasheet und Speedgrade -7 (=7ns) //--------------------------------------------------------- FMC_SDRAMTimingInitStructure.FMC_LoadToActiveDelay = 2; // tMRD=2CLK FMC_SDRAMTimingInitStructure.FMC_ExitSelfRefreshDelay = 7; // tXSR min=70ns FMC_SDRAMTimingInitStructure.FMC_SelfRefreshTime = 4; // tRAS min=42ns FMC_SDRAMTimingInitStructure.FMC_RowCycleDelay = 7; // tRC min=63ns FMC_SDRAMTimingInitStructure.FMC_WriteRecoveryTime = 2; // tWR =2CLK FMC_SDRAMTimingInitStructure.FMC_RPDelay = 2; // tRP min=15ns FMC_SDRAMTimingInitStructure.FMC_RCDDelay = 2; // tRCD min=15ns FMC_SDRAMInitStructure.FMC_Bank = FMC_Bank2_SDRAM; FMC_SDRAMInitStructure.FMC_ColumnBitsNumber = FMC_ColumnBits_Number_8b; FMC_SDRAMInitStructure.FMC_RowBitsNumber = FMC_RowBits_Number_12b; FMC_SDRAMInitStructure.FMC_SDMemoryDataWidth = SDRAM_MEMORY_WIDTH; FMC_SDRAMInitStructure.FMC_InternalBankNumber = FMC_InternalBank_Number_4; FMC_SDRAMInitStructure.FMC_CASLatency = SDRAM_CAS_LATENCY; FMC_SDRAMInitStructure.FMC_WriteProtection = FMC_Write_Protection_Disable; FMC_SDRAMInitStructure.FMC_SDClockPeriod = SDRAM_CLOCK_PERIOD; FMC_SDRAMInitStructure.FMC_ReadBurst = SDRAM_READBURST; FMC_SDRAMInitStructure.FMC_ReadPipeDelay = FMC_ReadPipe_Delay_1; FMC_SDRAMInitStructure.FMC_SDRAMTimingStruct = &FMC_SDRAMTimingInitStructure; FMC_SDRAMInit(&FMC_SDRAMInitStructure); P_SDRAM_InitSequence(); }
void G8_PSRAM_Init(void) { FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef p; GPIO_InitTypeDef GPIO_InitStructure; RCC_ClocksTypeDef RCC_Clocks; /* Enable GPIOs clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG, ENABLE); /* Enable FSMC clock */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); RCC_AHB3PeriphResetCmd(RCC_AHB3Periph_FSMC, ENABLE); RCC_AHB3PeriphResetCmd(RCC_AHB3Periph_FSMC, DISABLE); RCC_GetClocksFreq(&RCC_Clocks); /*-- GPIOs Configuration -----------------------------------------------------*/ /* +-------------------+--------------------+------------------+------------------+ | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | | PD4 <-> FSMC_NOE | PE2 <-> FSMC_A23 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | | PD5 <-> FSMC_NWE | PE3 <-> FSMC_A19 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | | PD8 <-> FSMC_D13 | PE4 <-> FSMC_A20 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | | PD9 <-> FSMC_D14 | PE5 <-> FSMC_A21 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | | PD10 <-> FSMC_D15 | PE6 <-> FSMC_A22 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | | PD11 <-> FSMC_A16 | PE7 <-> FSMC_D4 | PF13 <-> FSMC_A7 |------------------+ | PD12 <-> FSMC_A17 | PE8 <-> FSMC_D5 | PF14 <-> FSMC_A8 | | PD13 <-> FSMC_A18 | PE9 <-> FSMC_D6 | PF15 <-> FSMC_A9 | | PD14 <-> FSMC_D0 | PE10 <-> FSMC_D7 |------------------+ | PD15 <-> FSMC_D1 | PE11 <-> FSMC_D8 | +-------------------| PE12 <-> FSMC_D9 | | PE13 <-> FSMC_D10 | | PE14 <-> FSMC_D11 | | PE15 <-> FSMC_D12 | +--------------------+ */ /* 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_PinSource0 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource1 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource2 , GPIO_AF_FSMC); 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_PinSource6 , 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_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | 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); /*-- FSMC Configuration ------------------------------------------------------*/ #if 1 if (RCC_Clocks.HCLK_Frequency == 150000000) { // tests to make PSRAM more reliable? slower? p.FSMC_AddressSetupTime = 3; // 2 definitely does not work p.FSMC_AddressHoldTime = 0; // 0 was the starting value. 1 and 2 worked, but did not fix the hard fault issue. I think this is a "don't care" for async access. p.FSMC_DataSetupTime = 9; //4 does not work at all (100% failure). 5 is poor (~50% success). 6,7 works (0% failure). // 9 works, and fixes the hard fault! 11 causes the code to vector to __exit, with no call stack. This value can go from 1 to 255. I think it needs to be at least 4. p.FSMC_BusTurnAroundDuration = 2; // for non-muxed memory, is "don't care" p.FSMC_CLKDivision = 1; // for async, this is "don't care". For sync access, the division is +1 this number , ie. (1-15) => (2-16). 0 is not allowed. p.FSMC_DataLatency = 1; // for PSRAM, this is "don't care" p.FSMC_AccessMode = FSMC_AccessMode_A; // since the EXTMOD =0, this is "don't care" } else { G8_SerialDebugWrite("HCLK frequency not supported."); // note that this code could support other frequencies, but it just is done yet. while(1); } double tRC = (p.FSMC_AddressSetupTime + p.FSMC_DataSetupTime)*1.0e9 / RCC_Clocks.HCLK_Frequency; if (tRC < 70.0 /* ns */) { G8_SerialDebugWrite("FSMC timing for Micron MT45... memory is too fast. 70 ns tRC"); while(1); } //// WAIT SIGNAL GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_FSMC); /// MTL. hook up WAIT signal GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOD, &GPIO_InitStructure); /// CRE signal GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_ResetBits(GPIOG,GPIO_Pin_6); // deassert FSMC_NORSRAMStructInit(&FSMC_NORSRAMInitStructure); FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; // FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Enable; 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_WaitSignal = FSMC_WaitSignal_Enable; FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; #else p.FSMC_AddressSetupTime = 3; p.FSMC_AddressHoldTime = 0; p.FSMC_DataSetupTime = 6; p.FSMC_BusTurnAroundDuration = 1; p.FSMC_CLKDivision = 0; p.FSMC_DataLatency = 0; p.FSMC_AccessMode = FSMC_AccessMode_A; FSMC_NORSRAMStructInit(&FSMC_NORSRAMInitStructure); FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; 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; #endif FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); /*!< Enable FSMC Bank1_SRAM2 Bank */ FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE); #if 0 // try to to read out BCR, etc registers { static struct { uint16_t RCR; uint16_t DIDR; uint16_t BCR; } micron; GPIO_SetBits(GPIOG,GPIO_Pin_6); // assert CRE #define MICRON_RCR__PageModeEnable 0x80 #define MICRON_RCR__DeepPowerDownDisable 0x10 #define MICRON_RCR__RefreshMask 0x07 #define MICRON_RCR__RefreshFullArray 0x00 micron.RCR = *(uint16_t*)(0x64000000 | (0 << (18+1))); // was 0x0010 #define MICRON_DIDR__RowLength 0x8000 // 0 = 128 words, 1 = 256 words #define MICRON_DIDR__DeviceVersionMask 0x7800 // #define MICRON_DIDR__DeviceDensityMask 0x0700 // 3 = 128MBit #define MICRON_DIDR__CellularRAMGenerationMask 0x00D0 // 2 = CellularRAM1.5 #define MICRON_DIDR__VendorIDMask 0x001F // 3 = Micron micron.DIDR = *(uint16_t*)(0x64000000 | (1 << (18+1))); // was 0x1B43 #define MICRON_BCR__OperationMode 0x8000 // 0 = sync, 1= async #define MICRON_BCR__InitialAccessLatency 0x4000 // 0 = variable, 1=fixed #define MICRON_BCR__LatencyCounterMask 0x3800 // 0 = Code8, 1 = Code1, ... 7 = Code7 Hmmm. Default is clamed to be 3, but I see 2 #define MICRON_BCR__WaitPolarity 0x0400 // 0 = active low, 1 = active high #define MICRON_BCR__WaitConfiguration 0x0100 // 0 = asserted during delay, 1 = asserted one data cycle before delay #define MICRON_BCR__DriveStengthMask 0x0030 // 0 = full, 1=half, 2=quarter,3=reserved #define MICRON_BCR__BurstWrap 0x0008 // 0 = wraps, 1= no wrap #define MICRON_BCR__BurstLengthMask 0x0003 // 1 = 4 words, 2 = 8 words, 3 = 16 words, 4 = 32 words, 7 continuous, micron.BCR = *(uint16_t*)(0x64000000 | (2 << (18+1))); /// was 0x9D1F GPIO_ResetBits(GPIOG,GPIO_Pin_6); // deassert CRE } #endif }
void sram_init(void) { GPIO_InitTypeDef GPIO_InitStructure; FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef readWriteTiming; /////////////////////////////////////////////////////////////////////// //// SRAM GPIO配置 //// /////////////////////////////////////////////////////////////////////// RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG, ENABLE);//使能PD,PE,PF,PG时钟 GPIO_InitStructure.GPIO_Pin = (3<<0)|(3<<4)|(0XFF<<8);//PD0,1,4,5,8~15 AF OUT GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用输出 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 GPIO_Init(GPIOD, &GPIO_InitStructure);//初始化 GPIO_InitStructure.GPIO_Pin = (3<<0)|(0X1FF<<7);//PE0,1,7~15,AF OUT GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用输出 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 GPIO_Init(GPIOE, &GPIO_InitStructure);//初始化 GPIO_InitStructure.GPIO_Pin = (0X3F<<0)|(0XF<<12); //PF0~5,12~15 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用输出 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 GPIO_Init(GPIOF, &GPIO_InitStructure);//初始化 GPIO_InitStructure.GPIO_Pin =(0X3F<<0)| GPIO_Pin_10;//PG0~5,10 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用输出 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 GPIO_Init(GPIOG, &GPIO_InitStructure);//初始化 GPIO_PinAFConfig(GPIOD,GPIO_PinSource0,GPIO_AF_FSMC);//PD0,AF12 GPIO_PinAFConfig(GPIOD,GPIO_PinSource1,GPIO_AF_FSMC);//PD1,AF12 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);//PD15,AF12 GPIO_PinAFConfig(GPIOE,GPIO_PinSource0,GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE,GPIO_PinSource1,GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE,GPIO_PinSource7,GPIO_AF_FSMC);//PE7,AF12 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);//PE15,AF12 GPIO_PinAFConfig(GPIOF,GPIO_PinSource0,GPIO_AF_FSMC);//PF0,AF12 GPIO_PinAFConfig(GPIOF,GPIO_PinSource1,GPIO_AF_FSMC);//PF1,AF12 GPIO_PinAFConfig(GPIOF,GPIO_PinSource2,GPIO_AF_FSMC);//PF2,AF12 GPIO_PinAFConfig(GPIOF,GPIO_PinSource3,GPIO_AF_FSMC);//PF3,AF12 GPIO_PinAFConfig(GPIOF,GPIO_PinSource4,GPIO_AF_FSMC);//PF4,AF12 GPIO_PinAFConfig(GPIOF,GPIO_PinSource5,GPIO_AF_FSMC);//PF5,AF12 GPIO_PinAFConfig(GPIOF,GPIO_PinSource12,GPIO_AF_FSMC);//PF12,AF12 GPIO_PinAFConfig(GPIOF,GPIO_PinSource13,GPIO_AF_FSMC);//PF13,AF12 GPIO_PinAFConfig(GPIOF,GPIO_PinSource14,GPIO_AF_FSMC);//PF14,AF12 GPIO_PinAFConfig(GPIOF,GPIO_PinSource15,GPIO_AF_FSMC);//PF15,AF12 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_PinSource10,GPIO_AF_FSMC); /////////////////////////////////////////////////////////////////////// //// FSMC配置 //// /////////////////////////////////////////////////////////////////////// RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC,ENABLE);//使能FSMC时钟 readWriteTiming.FSMC_AddressSetupTime = 0x01; //地址建立时间(ADDSET)为1个HCLK 1/168M=6ns readWriteTiming.FSMC_AddressHoldTime = 0x00; //地址保持时间(ADDHLD)模式A未用到 readWriteTiming.FSMC_DataSetupTime = 0x02; ////数据保持时间(DATAST)为2个HCLK 2*6=12ns readWriteTiming.FSMC_BusTurnAroundDuration = 0x00; readWriteTiming.FSMC_CLKDivision = 0x00; readWriteTiming.FSMC_DataLatency = 0x00; readWriteTiming.FSMC_AccessMode = FSMC_AccessMode_A; //模式A FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;// 使用NE3 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType =FSMC_MemoryType_SRAM;// FSMC_MemoryType_SRAM; //SRAM FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;//存储器数据宽度为16bit FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode =FSMC_BurstAccessMode_Disable;// FSMC_BurstAccessMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait=FSMC_AsynchronousWait_Disable; 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 = &readWriteTiming; FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &readWriteTiming; //读写同样时序 FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); //初始化FSMC配置 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE); // 使能BANK3 }
/* ********************************************************************************************************* * 函 数 名: 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 }
/*=====================================================================================================*/ void R61581_Config( void ) { GPIO_InitTypeDef GPIO_InitStruct; FSMC_NORSRAMInitTypeDef FSMC_InitStruct; FSMC_NORSRAMTimingInitTypeDef ReadWrite_TimingInitStruct; FSMC_NORSRAMTimingInitTypeDef Write_TimingInitStruct; /* FSMC Clk Init *************************************************************/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE, ENABLE); RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); /* FSMC AF *************************************************************/ 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_PinSource7, 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_PinSource14, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, 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); /* TFT_RST PC7 */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStruct); R61581_BLigConfig(); /* FSMC_D0 PD14 */ /* FSMC_D1 PD15 */ /* FSMC_D2 PD0 */ /* FSMC_D3 PD1 */ /* FSMC_D4 PE7 */ /* FSMC_D5 PE8 */ /* FSMC_D6 PE9 */ /* FSMC_D7 PE10 */ /* FSMC_D8 PE11 */ /* FSMC_D9 PE12 */ /* FSMC_D10 PE13 */ /* FSMC_D11 PE14 */ /* FSMC_D12 PE15 */ /* FSMC_D13 PD8 */ /* FSMC_D14 PD9 */ /* FSMC_D15 PD10 */ /* FSMC_RD PD4 */ /* FSMC_WR PD5 */ /* FSMC_CS PD7 */ /* FSMC_RS PD11 */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOD, &GPIO_InitStruct); GPIO_InitStruct.GPIO_Pin = 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_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOE, &GPIO_InitStruct); ReadWrite_TimingInitStruct.FSMC_AddressSetupTime = 0x01; ReadWrite_TimingInitStruct.FSMC_AddressHoldTime = 0x00; ReadWrite_TimingInitStruct.FSMC_DataSetupTime = 0x0f; ReadWrite_TimingInitStruct.FSMC_BusTurnAroundDuration = 0x00; ReadWrite_TimingInitStruct.FSMC_CLKDivision = 0x00; ReadWrite_TimingInitStruct.FSMC_DataLatency = 0x00; ReadWrite_TimingInitStruct.FSMC_AccessMode = FSMC_AccessMode_A; Write_TimingInitStruct.FSMC_AddressSetupTime = 0x01; Write_TimingInitStruct.FSMC_AddressHoldTime = 0x00; Write_TimingInitStruct.FSMC_DataSetupTime = 0x02; Write_TimingInitStruct.FSMC_BusTurnAroundDuration = 0x00; Write_TimingInitStruct.FSMC_CLKDivision = 0x00; Write_TimingInitStruct.FSMC_DataLatency = 0x00; Write_TimingInitStruct.FSMC_AccessMode = FSMC_AccessMode_A; FSMC_InitStruct.FSMC_Bank = FSMC_Bank1_NORSRAM1; FSMC_InitStruct.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_InitStruct.FSMC_MemoryType =FSMC_MemoryType_SRAM; FSMC_InitStruct.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_InitStruct.FSMC_BurstAccessMode =FSMC_BurstAccessMode_Disable; FSMC_InitStruct.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; FSMC_InitStruct.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_InitStruct.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_InitStruct.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_InitStruct.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_InitStruct.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_InitStruct.FSMC_ExtendedMode = FSMC_ExtendedMode_Enable; FSMC_InitStruct.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_InitStruct.FSMC_ReadWriteTimingStruct = &ReadWrite_TimingInitStruct; FSMC_InitStruct.FSMC_WriteTimingStruct = &Write_TimingInitStruct; FSMC_NORSRAMInit(&FSMC_InitStruct); FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); }
// Инициализируем FSMC контроллер, к которому подключен дисплей по шине Intel-8080 (D0...D15, RS, WR, RD, CS) // Шина данных дисплея 16 бит // Подключение дисплея к контроллеру: // FSMC D0 <-> LCD D0 // FSMC D1 <-> LCD D1 // FSMC D2 <-> LCD D2 // ... // FSMC D15 <-> LCD D15 // FSMC NWE <-> LCD WR // FSMC NOE <-> LCD RD // FSMC NE1 <-> LCD CS // FSMC A16 <-> LCD RS void Init_FSMC(void) { // Объявляем структуру для инициализации GPIO GPIO_InitTypeDef GPIO_InitStructure; // Включить тактирование портов GPIOD, GPIOE, и AFIO RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOC, ENABLE); // SRAM Data lines, NOE and NWE configuration // GPIOD выводы настроим как выходы GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |GPIO_Pin_11 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // режим альтернативной функции GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // частота 50 МГц GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // двухтактный выход GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // без подтяжки GPIO_Init(GPIOD, &GPIO_InitStructure); // выполняем инициализацию // GPIOD используются FSMC контроллером GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC); // GPIO D0 <-> FSMC D2 GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC); // GPIO D1 <-> FSMC D3 GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC); // GPIO D4 <-> FSMC NOE GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC); // GPIO D5 <-> FSMC NWE GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, GPIO_AF_FSMC); // GPIO D7 <-> FSMC NE1 GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FSMC); // GPIO D8 <-> FSMC D13 GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FSMC); // GPIO D9 <-> FSMC D14 GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FSMC); // GPIO D10 <-> FSMC D15 GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC); // GPIO D11 <-> FSMC A16 GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC); // GPIO D14 <-> FSMC D0 GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC); // GPIO D15 <-> FSMC D1 // GPIOE выводы настроим как выходы GPIO_InitStructure.GPIO_Pin = 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); // GPIOE используются FSMC контроллером GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FSMC); // GPIO E7 <-> FSMC D4 GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FSMC); // GPIO E8 <-> FSMC D5 GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FSMC); // GPIO E9 <-> FSMC D6 GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FSMC); // GPIO E10 <-> FSMC D7 GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_FSMC); // GPIO E11 <-> FSMC D8 GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_FSMC); // GPIO E12 <-> FSMC D9 GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_FSMC); // GPIO E13 <-> FSMC D10 GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_FSMC); // GPIO E14 <-> FSMC D11 GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_FSMC); // GPIO E15 <-> FSMC D12 // Настройка контроллера FSMC FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef p; // Включить тактирование FSMC RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); // SRAM Bank 1 // Конфигурация FSMC_Bank1_NORSRAM1 p.FSMC_AddressSetupTime = 0x6; p.FSMC_AddressHoldTime = 0; p.FSMC_DataSetupTime = 0x6; p.FSMC_BusTurnAroundDuration = 0; p.FSMC_CLKDivision = 0; p.FSMC_DataLatency = 0; p.FSMC_AccessMode = FSMC_AccessMode_A; // Color LCD configuration // LCD configured as follow: // - Data/Address MUX = Disable // - Memory Type = SRAM // - Data Width = 16bit // - Write Operation = Enable // - Extended Mode = Enable // - Asynchronous Wait = Disable */ FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; 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 NOR/SRAM Bank1 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); }
void enableGPIOPowerUsageAndNoiseReductions(void) { RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | #ifdef STM32F40_41xxx RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOH | RCC_AHB1Periph_GPIOI | #endif RCC_AHB1Periph_CRC | RCC_AHB1Periph_FLITF | RCC_AHB1Periph_SRAM1 | RCC_AHB1Periph_SRAM2 | RCC_AHB1Periph_BKPSRAM | RCC_AHB1Periph_DMA1 | RCC_AHB1Periph_DMA2 | 0, ENABLE ); RCC_AHB2PeriphClockCmd(0, ENABLE); #ifdef STM32F40_41xxx RCC_AHB3PeriphClockCmd(0, ENABLE); #endif RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4 | RCC_APB1Periph_TIM5 | RCC_APB1Periph_TIM6 | RCC_APB1Periph_TIM7 | RCC_APB1Periph_TIM12 | RCC_APB1Periph_TIM13 | RCC_APB1Periph_TIM14 | RCC_APB1Periph_WWDG | RCC_APB1Periph_SPI2 | RCC_APB1Periph_SPI3 | RCC_APB1Periph_USART2 | RCC_APB1Periph_USART3 | RCC_APB1Periph_UART4 | RCC_APB1Periph_UART5 | RCC_APB1Periph_I2C1 | RCC_APB1Periph_I2C2 | RCC_APB1Periph_I2C3 | RCC_APB1Periph_CAN1 | RCC_APB1Periph_CAN2 | RCC_APB1Periph_PWR | RCC_APB1Periph_DAC | 0, ENABLE); RCC_APB2PeriphClockCmd( RCC_APB2Periph_TIM1 | RCC_APB2Periph_TIM8 | RCC_APB2Periph_USART1 | RCC_APB2Periph_USART6 | RCC_APB2Periph_ADC | RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 | RCC_APB2Periph_ADC3 | RCC_APB2Periph_SDIO | RCC_APB2Periph_SPI1 | RCC_APB2Periph_SYSCFG | RCC_APB2Periph_TIM9 | RCC_APB2Periph_TIM10 | RCC_APB2Periph_TIM11 | 0, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // default is un-pulled input GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Pin &= ~(GPIO_Pin_11 | GPIO_Pin_12); // leave USB D+/D- alone GPIO_InitStructure.GPIO_Pin &= ~(GPIO_Pin_13 | GPIO_Pin_14); // leave JTAG pins alone GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOE, &GPIO_InitStructure); #ifdef STM32F40_41xxx GPIO_Init(GPIOF, &GPIO_InitStructure); GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_Init(GPIOH, &GPIO_InitStructure); GPIO_Init(GPIOI, &GPIO_InitStructure); #endif }
/* +-------------------+--------------------+------------------+-------------------+ + STM32 FSMC pins assignment + +-------------------+--------------------+------------------+-------------------+ | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | | PD4 <-> FSMC_NOE | PE3 <-> FSMC_A19 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | | PD5 <-> FSMC_NWE | PE4 <-> FSMC_A20 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | | PD8 <-> FSMC_D13 | PE7 <-> FSMC_D4 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | | PD9 <-> FSMC_D14 | PE8 <-> FSMC_D5 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | | PD10 <-> FSMC_D15 | PE9 <-> FSMC_D6 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | | PD11 <-> FSMC_A16 | PE10 <-> FSMC_D7 | PF13 <-> FSMC_A7 | PG12 <-> FSMC_NE4 | | PD12 <-> FSMC_A17 | PE11 <-> FSMC_D8 | PF14 <-> FSMC_A8 |-------------------+ | PD13 <-> FSMC_A18 | PE12 <-> FSMC_D9 | PF15 <-> FSMC_A9 | | PD14 <-> FSMC_D0 | PE13 <-> FSMC_D10 |------------------+ | PD15 <-> FSMC_D1 | PE14 <-> FSMC_D11 | | PD7 <-> FSMC_NE1 | PE15 <-> FSMC_D12 | +-------------------+--------------------+ */ void fsmc_gpio_init(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIOs clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG, ENABLE); /* Enable FSMC clock */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); /* 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_PinSource6, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, 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); /* GPIOE configuration */ GPIO_PinAFConfig(GPIOE, GPIO_PinSource0 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource1 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource3 , GPIO_AF_FSMC); //GPIO_PinAFConfig(GPIOE, GPIO_PinSource4 , 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); /* 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); /* 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_PinAFConfig(GPIOG, GPIO_PinSource12 , GPIO_AF_FSMC); 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_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | 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(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3 | 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); 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); 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_Pin_12; GPIO_Init(GPIOG, &GPIO_InitStructure); }
void LCD_GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable the FSMC Clock */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); /* config lcd gpio clock base on FSMC */ /* Enable GPIOs clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE,ENABLE); /* config tft data lines base on FSMC * data lines,FSMC-D0~D15: PD 14 15 0 1,PE 7 8 9 10 11 12 13 14 15,PD 8 9 10 */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_14| GPIO_Pin_15; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10; GPIO_Init(GPIOE, &GPIO_InitStructure); /* config tft control lines base on FSMC * PD4-FSMC_NOE :LCD-RD * PD5-FSMC_NWE :LCD-WR * PD7-FSMC_NE1 :LCD-CS * PD11-FSMC_A16 :LCD-DC */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; /* config tft rst gpio */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_Init(GPIOC, &GPIO_InitStructure); LCD_AF_FSMC_Config(); }
void stm32_FsmcInit() { FSMC_NORSRAMInitTypeDef xNor; FSMC_NORSRAMTimingInitTypeDef xNorWriteTiming, xNorReadTiming; #if NANDFLASH_ENABLE FSMC_NANDInitTypeDef xNand; FSMC_NAND_PCCARDTimingInitTypeDef xNandWriteTiming, xNandReadTiming; #endif GPIO_InitTypeDef xGpio; u32 nBank; /* Enable GPIOs clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG, ENABLE); /*-- GPIO Configuration ------------------------------------------------------*/ /* +-------------------+--------------------+------------------+------------------+ + SRAM pins assignment + +-------------------+--------------------+------------------+------------------+ | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | | PD4 <-> FSMC_NOE | PE2 <-> FSMC_A23 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | | PD5 <-> FSMC_NWE | PE3 <-> FSMC_A19 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | | PD8 <-> FSMC_D13 | PE4 <-> FSMC_A20 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | | PD9 <-> FSMC_D14 | PE5 <-> FSMC_A21 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | | PD10 <-> FSMC_D15 | PE6 <-> FSMC_A22 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | | PD11 <-> FSMC_A16 | PE7 <-> FSMC_D4 | PF13 <-> FSMC_A7 |------------------+ | PD12 <-> FSMC_A17 | PE8 <-> FSMC_D5 | PF14 <-> FSMC_A8 |------------------+ | PD13 <-> FSMC_A18 | PE9 <-> FSMC_D6 | PF15 <-> FSMC_A9 |------------------+ | PD14 <-> FSMC_D0 | PE10 <-> FSMC_D7 ------------------+ | PD15 <-> FSMC_D1 | PE11 <-> FSMC_D8 ------------------+ +------------------ | PE12 <-> FSMC_D9 ------------------+ +------------------ | PE13 <-> FSMC_D10 ------------------+ +------------------ | PE14 <-> FSMC_D11 ------------------+ +------------------ | PE15 <-> FSMC_D12 ------------------+ +-------------------+--------------------+ */ /*-- GPIO ÅäÖÃ -----------------------------------------------------------*/ xGpio.GPIO_Mode = GPIO_Mode_AF; xGpio.GPIO_Speed = GPIO_Speed_100MHz; xGpio.GPIO_OType = GPIO_OType_PP; xGpio.GPIO_PuPd = GPIO_PuPd_NOPULL; xGpio.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | 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; /* 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); //FSMC_NOE GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC); //FSMC_NWE GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, GPIO_AF_FSMC); //FSMC_NE1 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_Init(GPIOD, &xGpio); /* GPIOE configuration */ xGpio.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | 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_PinAFConfig(GPIOE, GPIO_PinSource2 , GPIO_AF_FSMC); 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_PinSource6 , 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_Init(GPIOE, &xGpio); /* GPIOF configuration */ xGpio.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_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_Init(GPIOF, &xGpio); /* 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); xGpio.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, &xGpio); /* FSMC_NWAIT */ GPIO_PinAFConfig(GPIOD, GPIO_PinSource6 , GPIO_AF_FSMC); xGpio.GPIO_Pin = GPIO_Pin_6; xGpio.GPIO_Mode = GPIO_Mode_IN; xGpio.GPIO_Speed = GPIO_Speed_100MHz; xGpio.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOD, &xGpio); #if EXTSRAM_ENABLE #endif #if NANDFLASH_ENABLE #endif /* FSMC Clock Enable */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); #if NORFLASH_ENABLE nBank = stm32_Bank(NORFLASH_BASE_ADR); /*-- FSMC Configuration ----------------------------------------------------*/ xNorReadTiming.FSMC_AddressSetupTime = 5; xNorReadTiming.FSMC_AddressHoldTime = 0; xNorReadTiming.FSMC_DataSetupTime = 7; xNorReadTiming.FSMC_BusTurnAroundDuration = 0; xNorReadTiming.FSMC_CLKDivision = 0; xNorReadTiming.FSMC_DataLatency = 0; xNorReadTiming.FSMC_AccessMode = FSMC_AccessMode_B; xNorWriteTiming.FSMC_AddressSetupTime = 5; xNorWriteTiming.FSMC_AddressHoldTime = 0; xNorWriteTiming.FSMC_DataSetupTime = 7; xNorWriteTiming.FSMC_BusTurnAroundDuration = 0; xNorWriteTiming.FSMC_CLKDivision = 0; xNorWriteTiming.FSMC_DataLatency = 0; xNorWriteTiming.FSMC_AccessMode = FSMC_AccessMode_B; xNor.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; xNor.FSMC_MemoryType = FSMC_MemoryType_NOR; xNor.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; xNor.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; xNor.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; xNor.FSMC_WrapMode = FSMC_WrapMode_Disable; xNor.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; xNor.FSMC_WriteOperation = FSMC_WriteOperation_Enable; xNor.FSMC_WaitSignal = FSMC_WaitSignal_Disable; xNor.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; xNor.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; xNor.FSMC_WriteBurst = FSMC_WriteBurst_Disable; xNor.FSMC_ReadWriteTimingStruct = &xNorReadTiming; xNor.FSMC_WriteTimingStruct = &xNorWriteTiming; xNor.FSMC_Bank = nBank; FSMC_NORSRAMInit(&xNor); FSMC_NORSRAMCmd(nBank, ENABLE); #endif #if EXTSRAM_ENABLE nBank = stm32_Bank(EXTSRAM_BASE_ADR); /*-- FSMC Configuration ----------------------------------------------------*/ xNorReadTiming.FSMC_AddressSetupTime = 0; xNorReadTiming.FSMC_AddressHoldTime = 0; xNorReadTiming.FSMC_DataSetupTime = 2; xNorReadTiming.FSMC_BusTurnAroundDuration = 0; xNorReadTiming.FSMC_CLKDivision = 0; xNorReadTiming.FSMC_DataLatency = 0; xNorReadTiming.FSMC_AccessMode = FSMC_AccessMode_A; xNorWriteTiming.FSMC_AddressSetupTime = 0; xNorWriteTiming.FSMC_AddressHoldTime = 0; xNorWriteTiming.FSMC_DataSetupTime = 2; xNorWriteTiming.FSMC_BusTurnAroundDuration = 0; xNorWriteTiming.FSMC_CLKDivision = 0; xNorWriteTiming.FSMC_DataLatency = 0; xNorWriteTiming.FSMC_AccessMode = FSMC_AccessMode_A; xNor.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; xNor.FSMC_MemoryType = FSMC_MemoryType_SRAM; xNor.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; xNor.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; xNor.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; xNor.FSMC_WrapMode = FSMC_WrapMode_Disable; xNor.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; xNor.FSMC_WriteOperation = FSMC_WriteOperation_Enable; xNor.FSMC_WaitSignal = FSMC_WaitSignal_Disable; xNor.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; xNor.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; xNor.FSMC_WriteBurst = FSMC_WriteBurst_Disable; xNor.FSMC_ReadWriteTimingStruct = &xNorReadTiming; xNor.FSMC_WriteTimingStruct = &xNorWriteTiming; xNor.FSMC_Bank = nBank; FSMC_NORSRAMInit(&xNor); FSMC_NORSRAMCmd(nBank, ENABLE); #endif #if GUI_ENABLE nBank = stm32_Bank(GUI_LCD_BASE_ADR); /*-- FSMC Configuration ----------------------------------------------------*/ xNorReadTiming.FSMC_AddressSetupTime = 1; xNorReadTiming.FSMC_AddressHoldTime = 0; xNorReadTiming.FSMC_DataSetupTime = 9; xNorReadTiming.FSMC_BusTurnAroundDuration = 0; xNorReadTiming.FSMC_CLKDivision = 0; xNorReadTiming.FSMC_DataLatency = 0; xNorReadTiming.FSMC_AccessMode = FSMC_AccessMode_A; xNorWriteTiming.FSMC_AddressSetupTime = 1; xNorWriteTiming.FSMC_AddressHoldTime = 0; xNorWriteTiming.FSMC_DataSetupTime = 9; xNorWriteTiming.FSMC_BusTurnAroundDuration = 0; xNorWriteTiming.FSMC_CLKDivision = 0; xNorWriteTiming.FSMC_DataLatency = 0; xNorWriteTiming.FSMC_AccessMode = FSMC_AccessMode_A; xNor.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; xNor.FSMC_MemoryType = FSMC_MemoryType_SRAM; xNor.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; xNor.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; xNor.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; xNor.FSMC_WrapMode = FSMC_WrapMode_Disable; xNor.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; xNor.FSMC_WriteOperation = FSMC_WriteOperation_Enable; xNor.FSMC_WaitSignal = FSMC_WaitSignal_Disable; xNor.FSMC_ExtendedMode = FSMC_ExtendedMode_Enable; xNor.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; xNor.FSMC_WriteBurst = FSMC_WriteBurst_Disable; xNor.FSMC_ReadWriteTimingStruct = &xNorReadTiming; xNor.FSMC_WriteTimingStruct = &xNorWriteTiming; xNor.FSMC_Bank = nBank; FSMC_NORSRAMInit(&xNor); FSMC_NORSRAMCmd(nBank, ENABLE); #endif #if DM9000_ENABLE nBank = stm32_Bank(DM9000_BASE_ADR); /*-- FSMC Configuration ----------------------------------------------------*/ xNorReadTiming.FSMC_AddressSetupTime = 0; xNorReadTiming.FSMC_AddressHoldTime = 0; xNorReadTiming.FSMC_DataSetupTime = 1; xNorReadTiming.FSMC_BusTurnAroundDuration = 0; xNorReadTiming.FSMC_CLKDivision = 0; xNorReadTiming.FSMC_DataLatency = 0; xNorReadTiming.FSMC_AccessMode = FSMC_AccessMode_A; xNorWriteTiming.FSMC_AddressSetupTime = 0; xNorWriteTiming.FSMC_AddressHoldTime = 0; xNorWriteTiming.FSMC_DataSetupTime = 1; xNorWriteTiming.FSMC_BusTurnAroundDuration = 0; xNorWriteTiming.FSMC_CLKDivision = 0; xNorWriteTiming.FSMC_DataLatency = 0; xNorWriteTiming.FSMC_AccessMode = FSMC_AccessMode_A; xNor.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; xNor.FSMC_MemoryType = FSMC_MemoryType_SRAM; xNor.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; xNor.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; xNor.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; xNor.FSMC_WrapMode = FSMC_WrapMode_Disable; xNor.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; xNor.FSMC_WriteOperation = FSMC_WriteOperation_Enable; xNor.FSMC_WaitSignal = FSMC_WaitSignal_Disable; xNor.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; xNor.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; xNor.FSMC_WriteBurst = FSMC_WriteBurst_Disable; xNor.FSMC_ReadWriteTimingStruct = &xNorReadTiming; xNor.FSMC_WriteTimingStruct = &xNorWriteTiming; xNor.FSMC_Bank = nBank; FSMC_NORSRAMInit(&xNor); FSMC_NORSRAMCmd(nBank, ENABLE); #endif #if NANDFLASH_ENABLE nBank = stm32_Bank(NAND_BASE_ADR); /*-- FSMC Configuration ------------------------------------------------------*/ xNandReadTiming.FSMC_SetupTime = 1; xNandReadTiming.FSMC_WaitSetupTime = 3; xNandReadTiming.FSMC_HoldSetupTime = 2; xNandReadTiming.FSMC_HiZSetupTime = 1; xNandWriteTiming.FSMC_SetupTime = 1; xNandWriteTiming.FSMC_WaitSetupTime = 3; xNandWriteTiming.FSMC_HoldSetupTime = 2; xNandWriteTiming.FSMC_HiZSetupTime = 1; xNand.FSMC_Waitfeature = FSMC_Waitfeature_Enable; #if NAND_DATA_WIDTH == 16 xNand.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; #else xNand.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; #endif xNand.FSMC_ECC = FSMC_ECC_Disable; #if NAND_PAGE_DATA == 2048 xNand.FSMC_ECCPageSize = FSMC_ECCPageSize_2048Bytes; #else xNand.FSMC_ECCPageSize = FSMC_ECCPageSize_512Bytes; #endif xNand.FSMC_AddressLowMapping = FSMC_AddressLowMapping_Direct; xNand.FSMC_TCLRSetupTime = 0x00; xNand.FSMC_TARSetupTime = 0x00; xNand.FSMC_CommonSpaceTimingStruct = &xNandReadTiming; xNand.FSMC_AttributeSpaceTimingStruct = &xNandWriteTiming; xNand.FSMC_Bank = nBank; FSMC_NANDInit(&xNand); FSMC_NANDCmd(nBank, ENABLE); #endif }
/** * @brief FMC SDRAM Configuration * @param None * @retval None */ static void FMC_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; FMC_SDRAMInitTypeDef FMC_SDRAMInitStructure; FMC_SDRAMTimingInitTypeDef FMC_SDRAMTimingInitStructure; FMC_SDRAMCommandTypeDef FMC_SDRAMCommandStructure; uint32_t tmpr = 0; uint32_t timeout = SDRAM_TIMEOUT; /* GPIO configuration ------------------------------------------------------*/ /* Enable GPIOs clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOH | RCC_AHB1Periph_GPIOI, ENABLE); /* Common GPIO configuration */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; /* GPIOD configuration */ GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |GPIO_Pin_1 |GPIO_Pin_8 |GPIO_Pin_9 | GPIO_Pin_10 |GPIO_Pin_14 |GPIO_Pin_15; GPIO_Init(GPIOD, &GPIO_InitStructure); /* GPIOE configuration */ GPIO_PinAFConfig(GPIOE, GPIO_PinSource0 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource1 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_FMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | 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_FMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource1 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource2 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource3 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource4 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource5 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource11 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource12 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource13 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource14 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource15 , GPIO_AF_FMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_11 | 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_FMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource1 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource4 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource5 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource8 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource15 , GPIO_AF_FMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |GPIO_Pin_1 |GPIO_Pin_4 |GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_15; GPIO_Init(GPIOG, &GPIO_InitStructure); /* GPIOH configuration */ GPIO_PinAFConfig(GPIOH, GPIO_PinSource2 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOH, GPIO_PinSource3 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOH, GPIO_PinSource5 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOH, GPIO_PinSource8 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOH, GPIO_PinSource9 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOH, GPIO_PinSource10 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOH, GPIO_PinSource11 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOH, GPIO_PinSource12 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOH, GPIO_PinSource13 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOH, GPIO_PinSource14 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOH, GPIO_PinSource15 , GPIO_AF_FMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | 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_Init(GPIOH, &GPIO_InitStructure); /* GPIOI configuration */ GPIO_PinAFConfig(GPIOI, GPIO_PinSource0 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOI, GPIO_PinSource1 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOI, GPIO_PinSource2 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOI, GPIO_PinSource3 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOI, GPIO_PinSource4 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOI, GPIO_PinSource5 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOI, GPIO_PinSource6 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOI, GPIO_PinSource7 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOI, GPIO_PinSource9 , GPIO_AF_FMC); GPIO_PinAFConfig(GPIOI, GPIO_PinSource10 , GPIO_AF_FMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_9 | GPIO_Pin_10; GPIO_Init(GPIOI, &GPIO_InitStructure); /* Enable FMC clock */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE); /* FMC SDRAM device initialization sequence --------------------------------*/ /* Step 1 ----------------------------------------------------*/ /* Timing configuration for 84 Mhz of SD clock frequency (168Mhz/2) */ /* TMRD: 2 Clock cycles */ FMC_SDRAMTimingInitStructure.FMC_LoadToActiveDelay = 2; /* TXSR: min=70ns (6x11.90ns) */ FMC_SDRAMTimingInitStructure.FMC_ExitSelfRefreshDelay = 6; /* TRAS: min=42ns (4x11.90ns) max=120k (ns) */ FMC_SDRAMTimingInitStructure.FMC_SelfRefreshTime = 4; /* TRC: min=70 (6x11.90ns) */ FMC_SDRAMTimingInitStructure.FMC_RowCycleDelay = 6; /* TWR: min=1+ 7ns (1+1x11.90ns) */ FMC_SDRAMTimingInitStructure.FMC_WriteRecoveryTime = 2; /* TRP: 20ns => 2x11.90ns */ FMC_SDRAMTimingInitStructure.FMC_RPDelay = 2; /* TRCD: 20ns => 2x11.90ns */ FMC_SDRAMTimingInitStructure.FMC_RCDDelay = 2; /* Step 2 ----------------------------------------------------*/ /* FMC SDRAM control configuration */ FMC_SDRAMInitStructure.FMC_Bank = FMC_Bank1_SDRAM; /* Row addressing: [7:0] */ FMC_SDRAMInitStructure.FMC_ColumnBitsNumber = FMC_ColumnBits_Number_8b; /* Column addressing: [10:0] */ FMC_SDRAMInitStructure.FMC_RowBitsNumber = FMC_RowBits_Number_11b; FMC_SDRAMInitStructure.FMC_SDMemoryDataWidth = SDRAM_MEMORY_WIDTH; FMC_SDRAMInitStructure.FMC_InternalBankNumber = FMC_InternalBank_Number_4; /* CL: Cas Latency = 3 clock cycles */ FMC_SDRAMInitStructure.FMC_CASLatency = FMC_CAS_Latency_3; FMC_SDRAMInitStructure.FMC_WriteProtection = FMC_Write_Protection_Disable; FMC_SDRAMInitStructure.FMC_SDClockPeriod = SDCLOCK_PERIOD; FMC_SDRAMInitStructure.FMC_ReadBurst = FMC_Read_Burst_Enable; FMC_SDRAMInitStructure.FMC_ReadPipeDelay = FMC_ReadPipe_Delay_1; FMC_SDRAMInitStructure.FMC_SDRAMTimingStruct = &FMC_SDRAMTimingInitStructure; /* FMC SDRAM bank initialization */ FMC_SDRAMInit(&FMC_SDRAMInitStructure); /* Step 3 --------------------------------------------------------------------*/ /* Configure a clock configuration enable command */ FMC_SDRAMCommandStructure.FMC_CommandMode = FMC_Command_Mode_CLK_Enabled; FMC_SDRAMCommandStructure.FMC_CommandTarget = FMC_Command_Target_bank1; FMC_SDRAMCommandStructure.FMC_AutoRefreshNumber = 1; FMC_SDRAMCommandStructure.FMC_ModeRegisterDefinition = 0; /* Wait until the SDRAM controller is ready */ while((FMC_GetFlagStatus(FMC_Bank1_SDRAM, FMC_FLAG_Busy) != RESET) && (timeout > 0)) { timeout--; } /* Send the command */ FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStructure); /* Step 4 --------------------------------------------------------------------*/ /* Insert 100 ms delay */ Delay(10); /* Step 5 --------------------------------------------------------------------*/ /* Configure a PALL (precharge all) command */ FMC_SDRAMCommandStructure.FMC_CommandMode = FMC_Command_Mode_PALL; FMC_SDRAMCommandStructure.FMC_CommandTarget = FMC_Command_Target_bank1; FMC_SDRAMCommandStructure.FMC_AutoRefreshNumber = 1; FMC_SDRAMCommandStructure.FMC_ModeRegisterDefinition = 0; /* Wait until the SDRAM controller is ready */ timeout = SDRAM_TIMEOUT; while((FMC_GetFlagStatus(FMC_Bank1_SDRAM, FMC_FLAG_Busy) != RESET) && (timeout > 0)) { timeout--; } /* Send the command */ FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStructure); /* Step 6 --------------------------------------------------------------------*/ /* Configure a Auto-Refresh command */ FMC_SDRAMCommandStructure.FMC_CommandMode = FMC_Command_Mode_AutoRefresh; FMC_SDRAMCommandStructure.FMC_CommandTarget = FMC_Command_Target_bank1; FMC_SDRAMCommandStructure.FMC_AutoRefreshNumber = 8; FMC_SDRAMCommandStructure.FMC_ModeRegisterDefinition = 0; /* Wait until the SDRAM controller is ready */ timeout = SDRAM_TIMEOUT; while((FMC_GetFlagStatus(FMC_Bank1_SDRAM, FMC_FLAG_Busy) != RESET) && (timeout > 0)) { timeout--; } /* Send the command */ FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStructure); /* Step 7 --------------------------------------------------------------------*/ /* Program the external memory mode register */ tmpr = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_1 | SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL | SDRAM_MODEREG_CAS_LATENCY_3 | SDRAM_MODEREG_OPERATING_MODE_STANDARD | SDRAM_MODEREG_WRITEBURST_MODE_SINGLE; /* Configure a load Mode register command*/ FMC_SDRAMCommandStructure.FMC_CommandMode = FMC_Command_Mode_LoadMode; FMC_SDRAMCommandStructure.FMC_CommandTarget = FMC_Command_Target_bank1; FMC_SDRAMCommandStructure.FMC_AutoRefreshNumber = 1; FMC_SDRAMCommandStructure.FMC_ModeRegisterDefinition = tmpr; /* Wait until the SDRAM controller is ready */ timeout = SDRAM_TIMEOUT; while((FMC_GetFlagStatus(FMC_Bank1_SDRAM, FMC_FLAG_Busy) != RESET) && (timeout > 0)) { timeout--; } /* Send the command */ FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStructure); /* Step 8 --------------------------------------------------------------------*/ /* Set the refresh rate counter */ /* (7.81 us x Freq) - 20 */ /* Set the device refresh counter */ FMC_SetRefreshCount(636); /* Wait until the SDRAM controller is ready */ timeout = SDRAM_TIMEOUT; while((FMC_GetFlagStatus(FMC_Bank1_SDRAM, FMC_FLAG_Busy) != RESET) && (timeout > 0)) { timeout--; } }
/* 显示屏 连接方式 PD0/FSMC_D2 PD1/FSMC_D3 PD4/FSMC_NOE --- 读控制信号,OE = Output Enable , N 表示低有效 PD5/FSMC_NWE --- 写控制信号,WE = Output Enable , N 表示低有效 PD8/FSMC_D13 PD9/FSMC_D14 PD10/FSMC_D15 PD11/FSMC_A16 --- 地址 RS PD14/FSMC_D0 PD15/FSMC_D1 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 PD7/FSMC_NE1 --- 主片选(TFT) PE1 --> LCD_reset // PC3/TP_INT --- 触摸芯片中断 (对于RA8875屏,是RA8875输出的中断) 本例程未使用硬件中断 // ---- 下面是 TFT LCD接口其他信号 (FSMC模式不使用)---- // PD3/LCD_BUSY --- 触摸芯片忙 (RA8875屏是RA8875芯片的忙信号) // PF6/LCD_PWM --- LCD背光PWM控制 (RA8875屏无需此脚,背光由RA8875控制) // PI10/TP_NCS --- 触摸芯片的片选 (RA8875屏无需SPI接口触摸芯片) // PB3/SPI3_SCK --- 触摸芯片SPI时钟 (RA8875屏无需SPI接口触摸芯片) // PB4/SPI3_MISO --- 触摸芯片SPI数据线MISO(RA8875屏无需SPI接口触摸芯片) // PB5/SPI3_MOSI --- 触摸芯片SPI数据线MOSI(RA8875屏无需SPI接口触摸芯片) */ void BUS_dataAndAddress_config() { GPIO_InitTypeDef GPIO_InitStructure; /* 使能FSMC时钟 */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE , ENABLE); /* 设置 PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14), PD.10(D15), PD.14(D0), PD.15(D1) 为复用推挽输出 */ GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC); // F_D2 GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC); // F_D3 GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC); // F_NOE GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC); // F_NWR GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FSMC); // F_D13 GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FSMC); // F_D14 GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FSMC); // F_D15 GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC); // F_D0 GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC); // F_D1 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_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); /* 设置 PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10), PE.14(D11), PE.15(D12) 为复用推挽输出 */ // GPIO_PinAFConfig(GPIOE, GPIO_PinSource4 , GPIO_AF_FSMC); // GPIO_PinAFConfig(GPIOE, GPIO_PinSource5 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FSMC); // F_D4 GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FSMC); // F_D5 GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FSMC); // F_D6 GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FSMC); // F_D7 GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_FSMC); // F_D8 GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_FSMC); // F_D9 GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_FSMC); // F_D10 GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_FSMC); // F_D11 GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_FSMC); // F_D12 GPIO_InitStructure.GPIO_Pin = 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); /* 设置 PD.11(A16 (RS)) 为复用推挽输出 */ GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC); // F_A16 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_Init(GPIOD, &GPIO_InitStructure); /* 设置 PD7 (LCD/CS)) 为复用推挽输出 */ GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, GPIO_AF_FSMC); // F_NE1 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOD, &GPIO_InitStructure); /* 复位管脚 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_Init(GPIOE, &GPIO_InitStructure); // GPIO_InitTypeDef GPIO_InitStructure; // // enable time clock about gpio mode // RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | // RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE); // // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; //LCD-Reset==PE1 // GPIO_Init(GPIOE, &GPIO_InitStructure); // // // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // // Set PD.00(D2), PD.01(D3), // // PD.04(NOE/RD), PD.05(NWE/WR), PD.08(D13), PD.09(D14), // // PD.10(D15), PD.14(D0), PD.15(D1) as alternate function push pull // // 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_14 | GPIO_Pin_15; // GPIO_Init(GPIOD, &GPIO_InitStructure); // // // Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10), // // PE.14(D11), PE.15(D12) as alternate function push pull // GPIO_InitStructure.GPIO_Pin = 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); // // /* CS 为用FSMC_NE1(PD7) */ // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; // GPIO_Init(GPIOD, &GPIO_InitStructure); // // /* RS 为FSMC_A16(PD11)*/ // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ; // GPIO_Init(GPIOD, &GPIO_InitStructure); // GPIO_SetBits(GPIOD, GPIO_Pin_7); //CS=1 // GPIO_SetBits(GPIOD, GPIO_Pin_11); //RS=1 // GPIO_SetBits(GPIOD, GPIO_Pin_8| GPIO_Pin_9 |GPIO_Pin_10); // GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10); // GPIO_SetBits(GPIOE, GPIO_Pin_1); //RESET=1 // GPIO_SetBits(GPIOD, GPIO_Pin_4); //RD=1 // GPIO_SetBits(GPIOD, GPIO_Pin_5); //WR=1 }
/* This function configures 2 MiB SRAM memory mounted on STM3220G-EVAL board. It configures GPIOs and FSMC and to interface with the memory. It must be called before any operation on the SRAM. */ void SRAMconfigure() { FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStruct; FSMC_NORSRAMTimingInitTypeDef FSMC_NORSRAMTimingInitStruct; GPIO_InitTypeDef GPIO_InitStruct; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG, ENABLE); RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); /* GPIOs configuration +-------------------+--------------------+------------------+------------------+ + SRAM pins assignment + +-------------------+--------------------+------------------+------------------+ | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | | PD4 <-> FSMC_NOE | PE3 <-> FSMC_A19 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | | PD5 <-> FSMC_NWE | PE4 <-> FSMC_A20 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | | PD8 <-> FSMC_D13 | PE7 <-> FSMC_D4 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | | PD9 <-> FSMC_D14 | PE8 <-> FSMC_D5 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | | PD10 <-> FSMC_D15 | PE9 <-> FSMC_D6 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | | PD11 <-> FSMC_A16 | PE10 <-> FSMC_D7 | PF13 <-> FSMC_A7 |------------------+ | PD12 <-> FSMC_A17 | PE11 <-> FSMC_D8 | PF14 <-> FSMC_A8 | | PD13 <-> FSMC_A18 | PE12 <-> FSMC_D9 | PF15 <-> FSMC_A9 | | PD14 <-> FSMC_D0 | PE13 <-> FSMC_D10 |------------------+ | PD15 <-> FSMC_D1 | PE14 <-> FSMC_D11 | +-------------------| PE15 <-> FSMC_D12 | +--------------------+ */ GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; 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_InitStruct.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_Init(GPIOD, &GPIO_InitStruct); GPIO_PinAFConfig(GPIOE, GPIO_PinSource0, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource3, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource4, 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_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3 | GPIO_Pin_4 | 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_InitStruct); 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_InitStruct.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_InitStruct); 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_InitStruct.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_InitStruct); FSMC_NORSRAMTimingInitStruct.FSMC_AddressSetupTime = 0; FSMC_NORSRAMTimingInitStruct.FSMC_AddressHoldTime = 0; FSMC_NORSRAMTimingInitStruct.FSMC_DataSetupTime = 4; FSMC_NORSRAMTimingInitStruct.FSMC_BusTurnAroundDuration = 1; FSMC_NORSRAMTimingInitStruct.FSMC_CLKDivision = 0; FSMC_NORSRAMTimingInitStruct.FSMC_DataLatency = 0; FSMC_NORSRAMTimingInitStruct.FSMC_AccessMode = FSMC_AccessMode_A; FSMC_NORSRAMInitStruct.FSMC_Bank = FSMC_Bank1_NORSRAM2; FSMC_NORSRAMInitStruct.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStruct.FSMC_MemoryType = FSMC_MemoryType_PSRAM; FSMC_NORSRAMInitStruct.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_NORSRAMInitStruct.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; FSMC_NORSRAMInitStruct.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; FSMC_NORSRAMInitStruct.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStruct.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_NORSRAMInitStruct.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_NORSRAMInitStruct.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_NORSRAMInitStruct.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_NORSRAMInitStruct.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; FSMC_NORSRAMInitStruct.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_NORSRAMInitStruct.FSMC_ReadWriteTimingStruct = &FSMC_NORSRAMTimingInitStruct; FSMC_NORSRAMInitStruct.FSMC_WriteTimingStruct = &FSMC_NORSRAMTimingInitStruct; FSMC_NORSRAMInit(&FSMC_NORSRAMInitStruct); FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE); }
/** * @brief Configures the FSMC and GPIOs to interface with the OneNAND memory. * This function must be called before any write/read operation on the * OneNAND. * @param None * @retval None */ void OneNAND_Init(void) { FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef p; GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOB, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); /*-- GPIO Configuration ------------------------------------------------------*/ /* OneNAND Data lines configuration */ GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, 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(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_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_14 | GPIO_Pin_15 |GPIO_Pin_10; 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_UP; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = 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); /* OneNAND Address lines 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_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(GPIOD,GPIO_PinSource11, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD,GPIO_PinSource12, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD,GPIO_PinSource13, GPIO_AF_FSMC); 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_PinSource6, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE,GPIO_PinSource2, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG,GPIO_PinSource13, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG,GPIO_PinSource14, 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); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_13 | GPIO_Pin_14; GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4| GPIO_Pin_5 | GPIO_Pin_6; GPIO_Init(GPIOE, &GPIO_InitStructure); /* NOE, NWE and CLK configuration */ GPIO_PinAFConfig(GPIOD,GPIO_PinSource3, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD,GPIO_PinSource4, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD,GPIO_PinSource5, GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5 | GPIO_Pin_3; GPIO_Init(GPIOD, &GPIO_InitStructure); /* NE1 configuration */ GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOD, &GPIO_InitStructure); /* NL configuration */ GPIO_PinAFConfig(GPIOB,GPIO_PinSource7, GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOB, &GPIO_InitStructure); /* NWAIT Configuration */ GPIO_PinAFConfig(GPIOD,GPIO_PinSource6, GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_Init(GPIOD, &GPIO_InitStructure); /*-- FSMC Configuration ----------------------------------------------------*/ p.FSMC_AddressSetupTime = 0x03; p.FSMC_AddressHoldTime = 0x00; p.FSMC_DataSetupTime = 0x0C; p.FSMC_BusTurnAroundDuration = 0x01; p.FSMC_CLKDivision = 0x2; p.FSMC_DataLatency = 0x00; p.FSMC_AccessMode = FSMC_AccessMode_B; FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; 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_Enable; 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); FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); }