|
Keil下编译可以执行的代码,换到GCC编译器,编译成功,但在中断中读7606时,程序跑飞。
GCC不开优化的情况下,单步执行到i4ldata = *( __IO int32_t * )( ( ( uint32_t ) 0x60000000 ) );这句代码,程序直接跑飞。
但是开启任一优化如O1、Os,程序正常运行,AD7606读写正常。
各位坛友,有遇到过吗。
理论上来说,就算时序不对,也不应该程序跑飞。
以下是fsmc配置代码:
void FSMC_SRAM_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
/* Enable GPIOs clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE |
RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG , ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_SYSCFG, ENABLE);
/* 数据线 FSMC_D0--FSMC_D15 */
GPIO_InitStructure.GPIO_Pin = 0xC703;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = 0xFF80;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOD,GPIO_PinSource14,GPIO_AF_FSMC); //FSMC_D0
GPIO_PinAFConfig(GPIOD,GPIO_PinSource15,GPIO_AF_FSMC); //FSMC_D1
GPIO_PinAFConfig(GPIOD,GPIO_PinSource0, GPIO_AF_FSMC); //FSMC_D2
GPIO_PinAFConfig(GPIOD,GPIO_PinSource1, GPIO_AF_FSMC); //FSMC_D3
GPIO_PinAFConfig(GPIOE,GPIO_PinSource7, GPIO_AF_FSMC); //FSMC_D4
GPIO_PinAFConfig(GPIOE,GPIO_PinSource8, GPIO_AF_FSMC); //FSMC_D5
GPIO_PinAFConfig(GPIOE,GPIO_PinSource9, GPIO_AF_FSMC); //FSMC_D6
GPIO_PinAFConfig(GPIOE,GPIO_PinSource10,GPIO_AF_FSMC); //FSMC_D7
GPIO_PinAFConfig(GPIOE,GPIO_PinSource11,GPIO_AF_FSMC); //FSMC_D8
GPIO_PinAFConfig(GPIOE,GPIO_PinSource12,GPIO_AF_FSMC); //FSMC_D9
GPIO_PinAFConfig(GPIOE,GPIO_PinSource13,GPIO_AF_FSMC); //FSMC_D10
GPIO_PinAFConfig(GPIOE,GPIO_PinSource14,GPIO_AF_FSMC); //FSMC_D11
GPIO_PinAFConfig(GPIOE,GPIO_PinSource15,GPIO_AF_FSMC); //FSMC_D12
GPIO_PinAFConfig(GPIOD,GPIO_PinSource8, GPIO_AF_FSMC); //FSMC_D13
GPIO_PinAFConfig(GPIOD,GPIO_PinSource9, GPIO_AF_FSMC); //FSMC_D14
GPIO_PinAFConfig(GPIOD,GPIO_PinSource10,GPIO_AF_FSMC); //FSMC_D15
/* 地址线 FSMC_A0--FSMC_A25 */
GPIO_InitStructure.GPIO_Pin = 0xF03F;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOF,GPIO_PinSource0, GPIO_AF_FSMC); //FSMC_A
GPIO_PinAFConfig(GPIOF,GPIO_PinSource1, GPIO_AF_FSMC); //FSMC_A1
GPIO_PinAFConfig(GPIOF,GPIO_PinSource2, GPIO_AF_FSMC); //FSMC_A2
GPIO_PinAFConfig(GPIOF,GPIO_PinSource3, GPIO_AF_FSMC); //FSMC_A3
GPIO_PinAFConfig(GPIOF,GPIO_PinSource4, GPIO_AF_FSMC); //FSMC_A4
GPIO_PinAFConfig(GPIOF,GPIO_PinSource5, GPIO_AF_FSMC); //FSMC_A5
GPIO_PinAFConfig(GPIOF,GPIO_PinSource12,GPIO_AF_FSMC); //FSMC_A6
GPIO_PinAFConfig(GPIOF,GPIO_PinSource13,GPIO_AF_FSMC); //FSMC_A7
GPIO_PinAFConfig(GPIOF,GPIO_PinSource14,GPIO_AF_FSMC); //FSMC_A8
GPIO_PinAFConfig(GPIOF,GPIO_PinSource15,GPIO_AF_FSMC); //FSMC_A9
/* 读写信号 片选信号 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
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
/* Enable FSMC clock */
RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
p.FSMC_AccessMode = FSMC_AccessMode_A;
p.FSMC_AddressSetupTime = 3; //2
p.FSMC_AddressHoldTime = 0; //2
p.FSMC_DataSetupTime = 6; //4
p.FSMC_BusTurnAroundDuration = 2;
p.FSMC_CLKDivision = 0;
p.FSMC_DataLatency = 0;
/* FSMC Configuration */
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_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_Enable;//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);
}
以下是中断中的读7606代码:
void EXTI1_IRQHandler( void )
{
int32_t ui2data;
if ( EXTI_GetITStatus( EXTI_Line1 ) != RESET )
{
i4ldata = *( __IO int32_t * )( ( ( uint32_t ) 0x60000000 ) );
i4hdata = *( __IO int32_t * )( ( ( uint32_t ) 0x60000000 ) );
i3ldata = *( __IO int32_t * )( ( ( uint32_t ) 0x60000000 ) );
i3hdata = *( __IO int32_t * )( ( ( uint32_t ) 0x60000000 ) );
i2ldata = *( __IO int32_t * )( ( ( uint32_t ) 0x60000000 ) );
i2hdata = *( __IO int32_t * )( ( ( uint32_t ) 0x60000000 ) );
i1ldata = *( __IO int32_t * )( ( ( uint32_t ) 0x60000000 ) );
i1hdata = *( __IO int32_t * )( ( ( uint32_t ) 0x60000000 ) );
EXTI_ClearITPendingBit( EXTI_Line1 );
}
}
|
|