硬汉嵌入式论坛

 找回密码
 立即注册
查看: 7497|回复: 4
收起左侧

[有问必答] 如何設置 FSMC 的 Bank3 NE3  外接一顆  16bit 的 SRAM

[复制链接]

7

主题

12

回帖

33

积分

新手上路

积分
33
发表于 2013-9-20 09:30:04 | 显示全部楼层 |阅读模式
能否請教一下STM32F1   FSMC 的設置問題
我使用如下的程序設置FSMC 的 BANK1-NE4 一切正常(外接一顆 16bit 的 SRAM)
  /********* NE4 **************/
    /* FSMC讀速度設置 */
    FSMC_NORSRAMTimingInitStructure.FSMC_AddressSetupTime = 2; /* 地址建立時間  */
    FSMC_NORSRAMTimingInitStructure.FSMC_AddressHoldTime =  2;
    FSMC_NORSRAMTimingInitStructure.FSMC_DataSetupTime =  5;          /* 數據建立時間  */
    FSMC_NORSRAMTimingInitStructure.FSMC_BusTurnAroundDuration =  0;
    FSMC_NORSRAMTimingInitStructure.FSMC_CLKDivision =  5;
    FSMC_NORSRAMTimingInitStructure.FSMC_DataLatency =  5;
    FSMC_NORSRAMTimingInitStructure.FSMC_AccessMode = FSMC_AccessMode_A;    /* FSMC 訪問模式 */
    FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;
    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_Enable;
    //FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
    //FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
    //FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
    FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Enable;
    FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
    FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;
    FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
    /* FSMC寫速度設置 */
    FSMC_NORSRAMTimingInitStructure.FSMC_AddressSetupTime =  1;   //1  /* 地址建立時間  */
    FSMC_NORSRAMTimingInitStructure.FSMC_AddressHoldTime =   1;   //1
    FSMC_NORSRAMTimingInitStructure.FSMC_DataSetupTime =  15;     //5  /* 數據建立時間  */
    FSMC_NORSRAMTimingInitStructure.FSMC_BusTurnAroundDuration = 0;
    FSMC_NORSRAMTimingInitStructure.FSMC_CLKDivision =   1;       //1
    FSMC_NORSRAMTimingInitStructure.FSMC_DataLatency =   1;       //1
    FSMC_NORSRAMTimingInitStructure.FSMC_AccessMode = FSMC_AccessMode_A;    /* FSMC 訪問模式 */
    FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;
    FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);       //
    FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);   /* Enable FSMC Bank4_SRAM Bank */
    }                                             
/********************************/

但後來我還需要在 BANK3 上也接一顆相同的SRAM  時   
使用如下的程序設置Bank3    當CPU運行時卻會發生 Hard fault

    /********* NE3 **************/
    /* FSMC讀速度設置 */
    FSMC_NORSRAMTimingInitStructure.FSMC_AddressSetupTime = 2; /* 地址建立時間  */
    FSMC_NORSRAMTimingInitStructure.FSMC_AddressHoldTime =  2;
    FSMC_NORSRAMTimingInitStructure.FSMC_DataSetupTime =  5;          /* 數據建立時間  */
    FSMC_NORSRAMTimingInitStructure.FSMC_BusTurnAroundDuration =  0;
    FSMC_NORSRAMTimingInitStructure.FSMC_CLKDivision =  5;
    FSMC_NORSRAMTimingInitStructure.FSMC_DataLatency =  5;
    FSMC_NORSRAMTimingInitStructure.FSMC_AccessMode = FSMC_AccessMode_A;    /* FSMC 訪問模式 */
    FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;
    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_Enable;
    //FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
    //FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
    //FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
    FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Enable;
    FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
    FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;
    FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
    /* FSMC寫速度設置 */
    FSMC_NORSRAMTimingInitStructure.FSMC_AddressSetupTime =  1;   //1  /* 地址建立時間  */
    FSMC_NORSRAMTimingInitStructure.FSMC_AddressHoldTime =   1;   //1
    FSMC_NORSRAMTimingInitStructure.FSMC_DataSetupTime =  15;     //5  /* 數據建立時間  */
    FSMC_NORSRAMTimingInitStructure.FSMC_BusTurnAroundDuration = 0;
    FSMC_NORSRAMTimingInitStructure.FSMC_CLKDivision =   1;       //1
    FSMC_NORSRAMTimingInitStructure.FSMC_DataLatency =   1;       //1
    FSMC_NORSRAMTimingInitStructure.FSMC_AccessMode = FSMC_AccessMode_A;    /* FSMC 訪問模式 */
    FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;
    FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);       //
    FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);   /* Enable FSMC Bank4_SRAM Bank */
    }                                             
/********************************/

想請教一下   我該如何設置 FSMC 的 Bank3 NE3  外接一顆  16bit 的 SRAM
知道越多才明白自己懂的少得可憐
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107379
QQ
发表于 2013-9-20 10:34:33 | 显示全部楼层
NE1----NE4的配置应该是一样的,是不是你NE3的GPIO没有配置啊,
还有一个问题就是:
    p.FSMC_AddressSetupTime = 1;   //主要配置这个和第三个就可以了,其余的取0就行。
    p.FSMC_AddressHoldTime = 0;
    p.FSMC_DataSetupTime = 2;
    p.FSMC_BusTurnAroundDuration = 0;
    p.FSMC_CLKDivision = 0;
    p.FSMC_DataLatency = 0;


你今天先解决下,我明天回实验室了,把我的那个程序发上来。
回复

使用道具 举报

7

主题

12

回帖

33

积分

新手上路

积分
33
 楼主| 发表于 2013-9-20 16:35:26 | 显示全部楼层
感謝版主大哥的幫忙

我在前面有下面這幾行程序



   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

   /* NE3 configuration */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 |     //nNE3
                                                        GPIO_Pin_12 ;     //nNE4
    GPIO_Init(GPIOG, &GPIO_InitStructure);

但NE4所接的SRAM 讀寫都OK
NE3的就是不行
找不到我哪裡錯了
知道越多才明白自己懂的少得可憐
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107379
QQ
发表于 2013-9-21 15:41:21 | 显示全部楼层
  1. void SRAM_Init(void)
  2. {
  3.     FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;
  4.     FSMC_NORSRAMTimingInitTypeDef  p;
  5.     GPIO_InitTypeDef GPIO_InitStructure;
  6.     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  7.         
  8.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOG | RCC_APB2Periph_GPIOE |
  9.                          RCC_APB2Periph_GPIOF, ENABLE);
  10.    
  11.     /* 配置SRAM数据线 */
  12.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
  13.                                 GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
  14.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  15.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  16.     GPIO_Init(GPIOD, &GPIO_InitStructure);
  17.    
  18.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
  19.                                 GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
  20.                                 GPIO_Pin_15;
  21.     GPIO_Init(GPIOE, &GPIO_InitStructure);
  22.    
  23.     /* 配置SRAM 地址线 */
  24.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
  25.                                 GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |
  26.                                 GPIO_Pin_14 | GPIO_Pin_15;
  27.     GPIO_Init(GPIOF, &GPIO_InitStructure);
  28.    
  29.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
  30.                                 GPIO_Pin_4 | GPIO_Pin_5;
  31.     GPIO_Init(GPIOG, &GPIO_InitStructure);
  32.    
  33.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
  34.     GPIO_Init(GPIOD, &GPIO_InitStructure);
  35.    
  36.     /* 配置 NOE 和 NWE */  
  37.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
  38.     GPIO_Init(GPIOD, &GPIO_InitStructure);
  39.    
  40.     /* 配置 NE3 */
  41.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  42.     GPIO_Init(GPIOG, &GPIO_InitStructure);
  43.    
  44.     /* 配置 NBL0, NBL1 */
  45.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
  46.     GPIO_Init(GPIOE, &GPIO_InitStructure);
  47.    
  48.     /* 配置FSMC */
  49.     p.FSMC_AddressSetupTime =3;
  50.     p.FSMC_AddressHoldTime = 0;
  51.     p.FSMC_DataSetupTime = 6;           /* 根据SRAM的最大速度进行调整  */
  52.     p.FSMC_BusTurnAroundDuration = 0;
  53.     p.FSMC_CLKDivision = 0;
  54.     p.FSMC_DataLatency = 0;
  55.     p.FSMC_AccessMode = FSMC_AccessMode_A;
  56.    
  57.     FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;
  58.     FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
  59.     FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
  60.     FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
  61.     FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
  62.     FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;  
  63.     FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
  64.     FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
  65.     FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
  66.     FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
  67.     FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
  68.     FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  69.     FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
  70.     FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
  71.     FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
  72.    
  73.     FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
  74.    
  75.     /*!< Enable FSMC Bank1_SRAM Bank */
  76.     FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);  
  77. }
复制代码
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107379
QQ
发表于 2013-9-21 15:47:52 | 显示全部楼层
armfly - v2和v3都是用的NE3,对比了下,初始化,发现了一个不同的地方
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;   你的这个是使能的,我的这里是禁止的。
这个是3.5.0以后的库版本才加上的。以前的版本是没有的。

其它的地方你再试试看
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-29 05:23 , Processed in 0.266656 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表