4662|1

45

帖子

0

TA的资源

一粒金砂(中级)

楼主
 

STM32F205单片机通过FSMC 读写铁电存储器 FM22L16 数据发生偏移 [复制链接]

10芯积分
STM32F205单片机通过FSMC 读写铁电存储器 FM22L16,当我直接运行程序,先在一个开始的地址那里把一定长度的数据写进存储器,然后再在同样的地址处,读取同样的长度的数据,下载,运行,写进去的数据和读出来的数据应该是一样的,因为我程序里面做了一个判断,如果两者数据是一样的话,就会点亮开发板上面的LED灯,否则,不能点亮LED灯。现在的现象是,LED能被点亮,说明两者的数据是一样的。


但是当我单步调试的时候,写入的数据和读取出来的数据就不一样了,读取出来的数据比写进去的数据多了0x80,(这是我在watch窗口看到的)掉电之后也是一样的情况,再次读取里面的数据,也是一样的情形,不知道这是为什么??


还有,这个铁电存储器 的框架如下,但是使用FSMC的时候,我该怎么选择不同的块呢?有8 个 32K * 16 的块 ,FSMC里面如何选择操作?

下面附上程序:
  1. void SRAM_Init(void)
  2. {
  3.   FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;
  4.   FSMC_NORSRAMTimingInitTypeDef  p;
  5.   GPIO_InitTypeDef GPIO_InitStructure;
  6.   
  7.   /* Enable GPIOs clock */
  8.   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF |
  9.                          RCC_AHB1Periph_GPIOG, ENABLE);

  10.   /* Enable FSMC clock */
  11.   RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
  12.   
  13. /*-- GPIOs Configuration
  14.         ------------------+-----------------------+-------------------------+
  15.         PF0  <-> FSMC_A0        |                PD14 <-> FSMC_D0                |                PD5  <-> FSMC_NWE                        |
  16.         PF1  <-> FSMC_A1        |                PD15 <-> FSMC_D1                |   PD4  <-> FSMC_NOE                        |
  17.         PF2  <-> FSMC_A2        |                PD0  <-> FSMC_D2                |                PE0  <-> FSMC_NBL0                |
  18.         PF3  <-> FSMC_A3        |                PD1  <-> FSMC_D3                |                PE1  <-> FSMC_NBL1                |
  19.         PF4  <-> FSMC_A4        |                PE7  <-> FSMC_D4                |                                                                                                        |
  20.         PF5  <-> FSMC_A5        |                PE8  <-> FSMC_D5                |         //以下的PG10:(U2-CE)                |
  21.         PF12 <-> FSMC_A6        |                PE9  <-> FSMC_D6                |   PG10 <-> FSMC_NCE4_1  |
  22.         PF13 <-> FSMC_A7        |                PE10 <-> FSMC_D7    |-------------------------+
  23.         PF14 <-> FSMC_A8        |                PE11 <-> FSMC_D8                |
  24.         PF15 <-> FSMC_A9        |                PE12 <-> FSMC_D9                |
  25.         PG0  <-> FSMC_A10 |                PE13 <-> FSMC_D10                |
  26.         PG1  <-> FSMC_A11 |                PE14 <-> FSMC_D11         |
  27.         PG2  <-> FSMC_A12 |                PE15 <-> FSMC_D12         |
  28.         PG3  <-> FSMC_A13 |                PD8  <-> FSMC_D13                |
  29.         PG4  <-> FSMC_A14 |                PD9  <-> FSMC_D14                |
  30.         PG5  <-> FSMC_A15 |                PD10 <-> FSMC_D15                |
  31.         PD11 <-> FSMC_A16 |-----------------------+
  32.         PD12 <-> FSMC_A17 |               
  33. --------------------+*/


  34.   /* GPIOD configuration */
  35.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC);
  36.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC);
  37.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC);
  38.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC);
  39.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FSMC);
  40.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FSMC);
  41.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FSMC);
  42.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC);
  43.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_FSMC);
  44.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC);
  45.   GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC);

  46.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0  | GPIO_Pin_1  | GPIO_Pin_4  | GPIO_Pin_5  |
  47.                                 GPIO_Pin_8  | GPIO_Pin_9  | GPIO_Pin_10 | GPIO_Pin_11 |
  48.                                 GPIO_Pin_12 | GPIO_Pin_14 | GPIO_Pin_15;
  49.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  50.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  51.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  52.   GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
  53.   GPIO_Init(GPIOD, &GPIO_InitStructure);


  54.   /* GPIOE configuration */
  55.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource0 , GPIO_AF_FSMC);
  56.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource1 , GPIO_AF_FSMC);
  57.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FSMC);
  58.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FSMC);
  59.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FSMC);
  60.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FSMC);
  61.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_FSMC);
  62.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_FSMC);
  63.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_FSMC);
  64.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_FSMC);
  65.   GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_FSMC);

  66.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0  | GPIO_Pin_1  | GPIO_Pin_7  | GPIO_Pin_8 |
  67.                                 GPIO_Pin_9  | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12|
  68.                                                                                                                                 GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
  69.   GPIO_Init(GPIOE, &GPIO_InitStructure);


  70.   /* GPIOF configuration */
  71.   GPIO_PinAFConfig(GPIOF, GPIO_PinSource0 , GPIO_AF_FSMC);
  72.   GPIO_PinAFConfig(GPIOF, GPIO_PinSource1 , GPIO_AF_FSMC);
  73.   GPIO_PinAFConfig(GPIOF, GPIO_PinSource2 , GPIO_AF_FSMC);
  74.   GPIO_PinAFConfig(GPIOF, GPIO_PinSource3 , GPIO_AF_FSMC);
  75.   GPIO_PinAFConfig(GPIOF, GPIO_PinSource4 , GPIO_AF_FSMC);
  76.   GPIO_PinAFConfig(GPIOF, GPIO_PinSource5 , GPIO_AF_FSMC);
  77.   GPIO_PinAFConfig(GPIOF, GPIO_PinSource12 , GPIO_AF_FSMC);
  78.   GPIO_PinAFConfig(GPIOF, GPIO_PinSource13 , GPIO_AF_FSMC);
  79.   GPIO_PinAFConfig(GPIOF, GPIO_PinSource14 , GPIO_AF_FSMC);
  80.   GPIO_PinAFConfig(GPIOF, GPIO_PinSource15 , GPIO_AF_FSMC);
  81.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0  | GPIO_Pin_1  | GPIO_Pin_2  | GPIO_Pin_3  |
  82.                                 GPIO_Pin_4  | GPIO_Pin_5  | GPIO_Pin_12 | GPIO_Pin_13 |
  83.                                 GPIO_Pin_14 | GPIO_Pin_15;      
  84.   GPIO_Init(GPIOF, &GPIO_InitStructure);


  85.   /* GPIOG configuration */
  86.   GPIO_PinAFConfig(GPIOG, GPIO_PinSource0 , GPIO_AF_FSMC);
  87.   GPIO_PinAFConfig(GPIOG, GPIO_PinSource1 , GPIO_AF_FSMC);
  88.   GPIO_PinAFConfig(GPIOG, GPIO_PinSource2 , GPIO_AF_FSMC);
  89.   GPIO_PinAFConfig(GPIOG, GPIO_PinSource3 , GPIO_AF_FSMC);
  90.   GPIO_PinAFConfig(GPIOG, GPIO_PinSource4 , GPIO_AF_FSMC);
  91.   GPIO_PinAFConfig(GPIOG, GPIO_PinSource5 , GPIO_AF_FSMC);
  92.   GPIO_PinAFConfig(GPIOG, GPIO_PinSource10 , GPIO_AF_FSMC);

  93.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0  | GPIO_Pin_1  | GPIO_Pin_2  | GPIO_Pin_3 |
  94.                                 GPIO_Pin_4  | GPIO_Pin_5  |GPIO_Pin_10 ;      
  95.   GPIO_Init(GPIOG, &GPIO_InitStructure);
  96. /**************************************************************************************
  97. **FSMC_AddressSetupTime:
  98. <Defines the number of HCLK cycles to configurethe duration of the address setup time.
  99. This parameter can be a value between 0 and 0xF.
  100. @note This parameter is not used with synchronous NOR Flash memories.

  101. **FSMC_AddressHoldTime:
  102. < Defines the number of HCLK cycles to configure the duration of the address hold time.
  103. This parameter can be a value between 0 and 0xF.
  104. @note This parameter is not used with synchronous NOR Flash memories.

  105. **FSMC_DataSetupTime:
  106. < Defines the number of HCLK cycles to configure the duration of the data setup time.
  107. This parameter can be a value between 0 and 0xFF.
  108. @note This parameter is used for SRAMs, ROMs and asynchronous multiplexed NOR Flash memories.

  109. **FSMC_BusTurnAroundDuration:
  110. < Defines the number of HCLK cycles to configure the duration of the bus turnaround.
  111. This parameter can be a value between 0 and 0xF.
  112. @note This parameter is only used for multiplexed NOR Flash memories.

  113. **FSMC_CLKDivision:
  114. < Defines the period of CLK clock output signal, expressed in number of HCLK cycles.
  115. This parameter can be a value between 1 and 0xF.
  116. @note This parameter is not used for asynchronous NOR Flash, SRAM or ROM accesses.

  117. **FSMC_DataLatency:
  118. < Defines the number of memory clock cycles to issue to the memory before getting the first data.
  119. The parameter value depends on the memory type as shown below:
  120. - It must be set to 0 in case of a CRAM
  121. - It is don't care in asynchronous NOR, SRAM or ROM accesses
  122. - It may assume a value between 0 and 0xF in NOR Flash memories with synchronous burst mode enable

  123. **FSMC_AccessMode:
  124. < Specifies the asynchronous access mode. This parameter can be a value of @ref FSMC_Access_Mode
  125. ***************************************************************************************/

  126. /*-- FSMC Configuration  此函数需要详细配置-------------------------------------*/
  127.   p.FSMC_AddressSetupTime = 0;// Defines the number of HCLK cycles to configure the duration of the address setup time,(0~0xF),not use in NOR FLash
  128.   p.FSMC_AddressHoldTime = 0; // Defines the number of HCLK cycles to configure the duration of the address hold time (0~0xF)   not use in NOR FLash
  129.   p.FSMC_DataSetupTime = 4;   // Defines the number of HCLK cycles to configure the duration of the duration of the data setup time(0~0xF)  use in NOR SRAMs ROMs
  130.   p.FSMC_BusTurnAroundDuration = 1; //Defines the number of HCLK cycles to configure the duration of the bus turnaround(0~0xF)  only used NOR FLash
  131.   p.FSMC_CLKDivision = 0;     //Defines the period of CLK clock output signal, expressed in number of HCLK cycles.This parameter can be a value between 1 and 0xF.  not use for NOR Flash SRAM ROM
  132.   p.FSMC_DataLatency = 0;     //Defines the number of memory clock cycles to issue to the memory before getting the first data
  133.   p.FSMC_AccessMode = FSMC_AccessMode_A; //Specifies the asynchronous(异步) access mode

  134.   FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;  //NOR Flash/PSRAM 控制器 BANK1的3子Bank
  135.   FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
  136. //  FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM;
  137.         FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
  138.   FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
  139.   FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
  140.   FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;  
  141.   FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
  142.   FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
  143.   FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
  144.   FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
  145.   FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
  146.   FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  147.   FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
  148.   FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;  //Timing Parameters for write and read access if the  ExtendedMode is not used
  149.   FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;      //Timing Parameters for write access if the  ExtendedMode is used

  150.   FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);

  151.   /*!< Enable FSMC FSMC_Bank1_NORSRAM3 Bank */
  152.   FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);

  153. }
  154. void SRAM_WriteBuffer(uint16_t* pBuffer, uint32_t WriteAddr, uint32_t NumHalfwordToWrite)
  155. {
  156.   for (; NumHalfwordToWrite != 0; NumHalfwordToWrite--) /* while there is data to write */
  157.   {
  158.     /* Transfer data to the memory */
  159.     *(uint16_t *) (Bank1_SRAM3_ADDR + WriteAddr) = *pBuffer++;

  160.     /* Increment the address*/
  161.     WriteAddr += 2;
  162.   }
  163. }

  164. void SRAM_ReadBuffer(uint16_t* pBuffer, uint32_t ReadAddr, uint32_t NumHalfwordToRead)
  165. {
  166.   for (; NumHalfwordToRead != 0; NumHalfwordToRead--) /* while there is data to read */
  167.   {
  168.     /* Read a half-word from the memory */
  169.     *pBuffer++ = *(__IO uint16_t*) (Bank1_SRAM3_ADDR + ReadAddr);

  170.     /* Increment the address*/
  171.     ReadAddr += 2;
  172.   }
  173. }

  174. /**
  175.   * 功能:填充整个缓存区
  176.   * 参数pBuffer: 指向需要填充的缓存区的指针
  177.   * 参数BufferSize: 填充的缓存区的大小
  178.   * 参数Offset: 缓存区中需要填充的第一个数据,然后是依次叠加
  179.   */
  180. void Fill_Buffer(uint16_t *pBuffer, uint16_t BufferLenght, uint32_t Offset)
  181. {
  182.   uint16_t IndexTmp = 0;
  183.   for (IndexTmp = 0; IndexTmp < BufferLenght; IndexTmp++ )
  184.   {
  185.     pBuffer[IndexTmp] = IndexTmp + Offset;
  186.   }
  187. }
复制代码


  1. 以下是主程序
  2. //         配置 FSMC Bank1 NOR Flash/SRAM 3 NOR Flash 控制器
  3.   SRAM_Init();
  4.   Fill_Buffer(TxBuffer, BUFFER_SIZE1, 0x32);               //填充数据
  5.   SRAM_WriteBuffer(TxBuffer, WRITE_READ_ADDR1, BUFFER_SIZE1); //将TxBuffer中的数据写入到指定区中
  6.   SRAM_ReadBuffer(RxBuffer, WRITE_READ_ADDR1, BUFFER_SIZE1);  //读取指定长度的数据到 RxBuffer

  7. // Read back SRAM memory and check content correctness   
  8.   for (Index = 0x00; (Index < BUFFER_SIZE1) && (WriteReadStatus == 0); Index++)
  9.   {
  10.     if (TxBuffer[Index] != (RxBuffer[Index]-0x00))   //掉电发生偏移,偏移量为 0x80   
  11.     {
  12.       WriteReadStatus++;
  13.     }
  14.   }       

  15.   if (WriteReadStatus == 0)   //OK , Turn on LD4,LD5
  16.   {
  17.                  GPIO_ResetBits(GPIOE, GPIO_Pin_2);   
  18.      GPIO_ResetBits(GPIOE, GPIO_Pin_3);
  19.   }
  20.   else    //fail  , Turn off LD4,LD5
  21.   {
  22.     GPIO_SetBits(GPIOE, GPIO_Pin_2);   
  23.     GPIO_SetBits(GPIOE, GPIO_Pin_3);
  24.   }
复制代码



此帖出自stm32/stm8论坛

最新回复

有了解一款叫做MRAM存储器的产品吗?可以看一下mram存储器的资料,跟铁电存储器类似,容量比铁电存储器大 资料共享 [attach]403992[/attach]  详情 回复 发表于 2019-3-5 09:54
点赞 关注
个人签名mo_正_pei
 

回复
举报

935

帖子

1

TA的资源

禁止发言

沙发
 
有了解一款叫做MRAM存储器的产品吗?可以看一下mram存储器的资料,跟铁电存储器类似,容量比铁电存储器大
资料共享
(, 下载次数: 1)
此帖出自stm32/stm8论坛
 
个人签名存储芯片/MCU/SRAM/PSRAM/DDR/FLASH/MRAM。web.www.sramsun.com  QQ3161422826 TEL:13751192923
 

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

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表