调试FSMC总线复用模式时主要遇到以下几点:
1、寄存器的配置,首先注意使能地址数据复用,其次要存储器类型选择FSMC_MemoryType_NOR,否则出现不了NADV信号。
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
2、注意个GPIO复用功能的使能,以及时钟确定使能。
3、地址总线。在16位模式访问时,访问地址的[25..0]位必须先左移一位.。才能正确输出地址信号,原因是,STM32会将地址右移一位后在输出。如果输出前不左移,会导致输出地址错误,比如当我们软件访问地址6000 0005H这个地址时,实际访问的地址是6000 0002H。为何右移一位?看中文数据手册327页。如下
如表可以知道。当16位访问时,STM32把内部地址总线和FSMC地址信号线正好错移了一位。
这个主要是在复用模式下遇到的,至于16位模式下的其他访问会不会遇到这种情况还不知道。待开发。
附FSMC配置程序和读函数:
p.FSMC_AddressSetupTime = 15;
p.FSMC_AddressHoldTime = 15;
p.FSMC_DataSetupTime = 15;
p.FSMC_BusTurnAroundDuration = 15;
p.FSMC_CLKDivision = 0;
p.FSMC_DataLatency = 0;
p.FSMC_AccessMode = FSMC_AccessMode_B; FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;
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_NORSRAM1, ENABLE);
读函数中地址一定要左移
#define FPGA_ADDRESS 0x60000000
#define FPGA_read(offset) *((volatile unsigned short int *)(FPGA_ADDRESS +(offset<<1)))