最近一阵,我用STM32F103VC芯片的总线和FPGA通讯,无论是仿真还有直接写FLASH运行,总是出现想不通的问题:在读时,时序正常,写时,FSMC失控:NE1一直=0,NADV一直方波,NWE也是方波!怎么改都没有用!下面附上相关设定程序:
// -----------------------------------------------
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_AFIO | RCC_APB2Periph_ADC1 |
RCC_APB2Periph_ADC2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, ENABLE); RCC_APB1Periph_TIM3, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 | RCC_APB1Periph_TIM3| RCC_APB1Periph_TIM4, ENABLE);
// FSMC 端口设定为复用推挽+50MHz
// PD7(NE1),PD6(NWAIT),PD5(NWE),PD4(NOE),PD1(DA3),PD0(DA2)
GPIOD->CRL&=0x0000ff00;
GPIOD->CRL|=0xb8bb00bb;
GPIOD->BSRR=0x00000040;
// PD15(DA1),PD14(DA0),PD10(DA15),PD9(DA14),PD8(DA13)
GPIOD->CRH&=0x00fff000;
GPIOD->CRH|=0xbb000bbb;
// PE7(DA4)
GPIOE->CRL&=0x0fffffff;
GPIOE->CRL|=0xb0000000;
// PE15(DA12),PE14(DA11),PE13(DA10),PE12(DA9),PE11(DA8),PE10(DA7),PE9(DA6),PE8(DA5)
GPIOE->CRH&=0x00000000;
GPIOE->CRH|=0xbbbbbbbb;
// PB7(NADV)
GPIOB->CRL&=0x0fffffff;
GPIOB->CRL|=0xb0000000;
//FSMC初始化
void FSMC_Init(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
//GPIO_InitTypeDef GPIO_InitStructure;
//* 7*12MHz=84MHz时有效
p.FSMC_AddressSetupTime = 0x05; //地址建立时间(1-16个HCLK)
p.FSMC_AddressHoldTime = 0x07; //地址保持时间(2-16个HCLK)
//p.FSMC_AddressHoldTime = 0x00; //地址保持时间(1-16个HCLK)
p.FSMC_DataSetupTime = 0x5; //数据建立时间(0:保留,1:2个HCLK,0xff:256个HCLK)
p.FSMC_BusTurnAroundDuration = 0x04; //总线恢复时间(1-16个HCLK)
p.FSMC_CLKDivision = 0x03; //时钟分频比(定义CLK时钟输出信号的周期)(0:保留,1-15表示1个CLK相当于2-16个HCLK)
p.FSMC_DataLatency = 0x06; //数据保持时间(2-17个周期)
//p.FSMC_AccessMode = FSMC_AccessMode_A; //访问模式共4种:A,B,C,D
p.FSMC_AccessMode = FSMC_AccessMode_B;
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
//FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //不复用
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable; //1b 复用
//FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; //存储器类型
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; //存储器类型
//FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR; //3b2b 存储器类型
//FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; //5b4b 数据总线位宽
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; //8b,成组模式不使能
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; //9b WAIT极性
//FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_High; //9b WAIT极性
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; //(10b)不允许直接的非对齐成组操作
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; //11b配置等待时序
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; //12b 写使能位
//FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; //13b 禁用NWAIT信号
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Enable; //13b 可用NWAIT信号
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; //14b 不使用FSMC_BWTR寄存器
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; //19b 写操作始终处于异步模式
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
//FSMC_Bank1->BCR1=0x5b;
//*(__IO uint32_t *) (0xa0000000)= 0x5b;
/* Enable FSMC Bank1_SRAM Bank */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}
#define WADD (0x200<<1)+0x60000000
#define WriteW() *(__IO vu16 *) (WADD)= W;
#define ReadR() R=*(__IO vu16 *) (WADD);
真想不通会有这种问题,第一次写操作后,FSMC出了问题,但还没有死机,还能仿真。当再一次操作总线时(读或写),整个芯片失控,退出仿真!!!请大侠指点,万分感谢!!! |