这是我的FSMC的配置代码:
#include "stm32f10x.h"
#include "FPGA_Config.h"
//使用第一块存储区,使用第一块,定义基地址
//#define Bank1_SRAM1_ADDR ((uint32_t)0x60000000)
/*******************************************************************************
名称:FSMC_Config(void)
功能:配置FSMC寄存器
参数:无
时间:2011.07.27
版本:1.0
注意:
*******************************************************************************/
void FSMC_Config(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; //定义NOR初始化数据结构体
FSMC_NORSRAMTimingInitTypeDef p; //定义NOR初始化时间参数结构体
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOG |
RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF, ENABLE);
//数据线引脚初始化,辅助控制器中使用了16根数据线
// d[0..3] d[13..15]
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15 | GPIO_Pin_0 | GPIO_Pin_1 |
GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// d[4..12]
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_PP; //复用推挽输出
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//地址线引脚初始化,调试使用12根地址线
// a[0..3]对应FSMC_AD[6..9],即PF[12..15]
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF, &GPIO_InitStructure);
// a[4..9]对应FSMC_AD[10..15],即PG[0..5]
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
GPIO_Pin_4 | GPIO_Pin_5;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOG, &GPIO_InitStructure);
// a[10..11]对应FSMC_AD[16..17],即PD[11..12]
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//控制信号线,NE1=FPGA_CS、NOE=NRD、NWE=NWE
//NOE and NWE configuration
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5|GPIO_Pin_7;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//CLK输出
// fsmc_clk
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// clk_out,MCO脚
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/*-- FSMC Configuration ------------------------------------------------------*/
p.FSMC_AddressSetupTime = 0;
p.FSMC_AddressHoldTime = 0;
p.FSMC_DataSetupTime = 5;
p.FSMC_BusTurnAroundDuration = 0;
p.FSMC_CLKDivision = 0;
p.FSMC_DataLatency = 0;
p.FSMC_AccessMode = FSMC_AccessMode_A;
//具体定义参见stm32f10x_fsmc.h第91行
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; //16位
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_Disable; //扩展模式位,读写使用相同时序
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; //写操作的同步成组传输协议位
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); //调用初始化函数,实现FSMC的配置
// Enable FSMC Bank1_SRAM Bank
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
}
void LED_Config(void)
{
//GPIO_Config
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//设置为推挽输出模式驱动LED灯
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//PE0红灯亮,PE1绿灯不亮
GPIO_SetBits(GPIOE,GPIO_Pin_1);
GPIO_ResetBits(GPIOE,GPIO_Pin_0);
}
这是main函数
int main(void)
{
/* Setup STM32 system (clock, PLL and Flash configuration) */
SystemInit();
/* Add your application code here
*/
//RCC_Config();
FSMC_Config();
//EXTI_Config();
LED_Config();
/* Infinite loop */
uint16_t * pBuffer;
uint32_t ReadAddr;
pBuffer=(uint16_t *)0x40c0;
ReadAddr=0x00040C00;
while(1)
{
//pBuffer=( uint16_t*)(ReadAddr+EXSRAM_ADDR);
*(__IO uint16_t *) (EXSRAM_ADDR+ReadAddr) =*pBuffer;
}
}
问题:
1.运行到main函数中的while循环后程序就不能调试了,单级break按钮后程序跳转至 B Default_Handler,请问这是怎么回事?不能直接指针操作吗?
2.我把main函数改为
int main(void)
{
/* Setup STM32 system (clock, PLL and Flash configuration) */
SystemInit();
/* Add your application code here
*/
//RCC_Config();
FSMC_Config();
//EXTI_Config();
LED_Config();
/* Infinite loop */
uint16_t * pBuffer;
uint32_t ReadAddr;
pBuffer=(uint16_t *)0x40c0;
ReadAddr=0x00040C00;
while(1)
{
pBuffer=( uint16_t*)(ReadAddr+EXSRAM_ADDR);
//*(__IO uint16_t *) (EXSRAM_ADDR+ReadAddr) =*pBuffer;
}
}
后,程序可以正常调试,但是地址线上看不到地址数据,请问是怎么回事?谢谢!
搞了两天了,头都大了,就是搞不明白咋回事!哪个大侠帮帮忙啊!!! |