打印

请教香版主,关于STM32F103ZE与FPGA通信地址问题。

[复制链接]
3063|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
emouse|  楼主 | 2011-4-28 16:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
项目中需要使用STM32和FPGA通信,使用的是地址线和数据线,在FPGA中根据STM32的读写模式A的时序完成写入和读取。之前的PCB设计中只使用了8跟数据线和8根地址线,调试过程中没有发现什么问题,在现在的PCB中使用了8根地址线和16根数据线,数据宽度也改成了16位,刚开始是读取数据不正确,后来发现了问题,STM32在16位数据宽度下有个内外地址映射的问题,只需要把FPGA中的设定的地址乘以2在STM32中访问就可以了,但是在写操作的时候会出现写当前地址的时候把后面的地址写成0的情况,比如说我给FPGA中定义的偏移地址0x01写一个16位数据,按照地址映射,在STM32中我把地址写入0x02,。实际测试发现这个地址上的数据是对的,但是FPGA中0x02地址上的数据也变成了00.

STM32中对应的几个函数的代码如下:
*******************************************************************************/
#include "STM32Lib\\stm32f10x.h"
#include "hal.h"

//使用第一块存储区,使用第四块,定义基地址
#define Bank1_SRAM4_ADDR    ((uint32_t)0x6c000000)     

/*******************************************************************************
名称:CPLD_Init(void)
功能:配置FSMC寄存器
参数:无
时间:2011.1.15
版本:1.0
注意:实际CPLD只用了8根地址线和8根数据线

  按照模式A-SRAM/PSRAM(CRAM)OE翻转模式配置读写时序时序图在STM32技术手册P332

  可以按照实际连接配置地址线数据线

  实际CPLD中可以更改敏感信号,对STM32的时序要求放宽
*******************************************************************************/
void CPLD_Init(void)
{



FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;

FSMC_NORSRAMTimingInitTypeDef  p;

GPIO_InitTypeDef GPIO_InitStructure;



RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOG |

RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF, ENABLE);

//数据线引脚初始化,辅助控制器中使用了16根数据线

//D 0 1 2 3 13 14 15

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 |GPIO_Pin_9 |


  GPIO_Pin_10|
GPIO_Pin_14 | GPIO_Pin_15;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
//复用推挽输出

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOD, &GPIO_InitStructure);

//D4-D12

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_Init(GPIOE, &GPIO_InitStructure);



//地址线引脚初始化,调试使用8根地址线

//A0-A7

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |

                              GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |

                              GPIO_Pin_14;

GPIO_Init(GPIOF, &GPIO_InitStructure);



//其他控制信号线,调试使用NE4、NOE、NWE


//NOE and NWE configuration  

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;

GPIO_Init(GPIOD, &GPIO_InitStructure);


//NE4 configuration

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;

GPIO_Init(GPIOG, &GPIO_InitStructure);



/*-- FSMC Configuration ------------------------------------------------------*/

p.FSMC_AddressSetupTime = 0;

p.FSMC_AddressHoldTime = 0;

p.FSMC_DataSetupTime = 1;

p.FSMC_BusTurnAroundDuration = 0;

p.FSMC_CLKDivision = 0;

p.FSMC_DataLatency = 0;

p.FSMC_AccessMode = FSMC_AccessMode_A;



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_AsynchronousWait = FSMC_AsynchronousWait_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_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;

FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;

FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;



FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);



// Enable FSMC Bank1_SRAM Bank

FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);



//CPLD 复位信号,这里使用普通IO PD7

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;


GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
//开漏输出

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//50M时钟速度

GPIO_Init(GPIOC, &GPIO_InitStructure);



GPIO_ResetBits(GPIOD, GPIO_Pin_7);

GPIO_SetBits(GPIOD, GPIO_Pin_7);
//根据CPLD程序设置低电平复位
}
/*******************************************************************************
名称:CPLD_Write
功能:CPLD写时序
参数:uint8_t pBuffer-写入的数据 uint32_t WriteAddr-写入的地址
时间:2011.1.15
版本:1.0
注意:在硬件设计中使用了八根地址线和数据线,因此以八位的数据写入
*******************************************************************************/
void CPLD_Write(uint16_t pBuffer, uint32_t WriteAddr)
{
    *(uint32_t *) (Bank1_SRAM4_ADDR + WriteAddr) = pBuffer;  
}

/*******************************************************************************
名称:uint16_t CPLD_Read(uint32_t ReadAddr)
功能:CPLD读
参数:uint32_t ReadAddr需要读取的地址,返回读取的值
时间:2011.4.26
版本:1.0
注意:在硬件设计中使用了16根地址线和数据线,因此以16位的数据写入
*******************************************************************************/
uint16_t CPLD_Read(uint32_t ReadAddr)
{

uint16_t pBuffer;

pBuffer = *(__IO uint32_t*) (Bank1_SRAM4_ADDR + ReadAddr);

return pBuffer;
}


FPGA中对应的代码如下
-- 写操作,模式A,时序图在数据手册p331
process(rst,fsmc_ne4,fsmc_nwe,adr_l,fsmc_noe) is  
begin

if rst='0' then

pwmfreq_reg
<=
"0000100111000100";--初始值设为2500,10K频率

pwmocr1_reg
<=
"0000001001110001";--初始值设为625 1/4

pwmocr2_reg
<=
"0000010011100010";--1/2

elsif(fsmc_nwe'event and fsmc_nwe='1') then

if((fsmc_noe and (not fsmc_ne4))='1') then

case (adr_l) is

when "00000000" =>
pwmfreq_reg
<=
data;

when "00000010" =>
pwmocr1_reg
<=
data;

when "00000100" =>
pwmocr2_reg
<=
data;

when others =>

pwmfreq_reg  <= pwmfreq_reg;

pwmocr1_reg  <= pwmocr1_reg;

pwmocr2_reg  <= pwmocr2_reg;

end case;

end if;

end if;
end process;


恳请指点
沙发
laokongzhuang| | 2011-7-26 10:54 | 只看该作者
顶贴!学习!

使用特权

评论回复
板凳
香水城| | 2011-7-26 11:12 | 只看该作者
项目中需要使用STM32和FPGA通信,使用的是地址线和数据线,在FPGA中根据STM32的读写模式A的时序完成写入和读取。之前的PCB设计中只使用了8跟数据线和8根地址线,调试过程中没有发现什么问题,在现在的PCB中使用了8根地址线和16根数据线,数据宽度也改成了16位,刚开始是读取数据不正确,后来发现了问题,STM32在16位数据宽度下有个内外地址映射的问题,只需要把FPGA中的设定的地址乘以2在STM32中访问就可以了,但是在写操作的时候会出现写当前地址的时候把后面的地址写成0的情况,比如说我给FPGA中定义的偏移地址0x01写一个16位数据,按照地址映射,在STM32中我把地址写入0x02,。实际测试发现这个地址上的数据是对的,但是FPGA中0x02地址上的数据也变成了00.
...
emouse 发表于 2011-4-28 16:44


不明白那句话(红字)是什么意思。更不明白“把地址写入0x02”是什么意思。

使用特权

评论回复
地板
panqi1986| | 2014-1-8 17:31 | 只看该作者
香主 他说的意思是不是说往0x6c000000基地址的偏移地址0x00000001中写了个值,结果0x00000002中的值被置为了0?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

88

帖子

4

粉丝