玩转FPGA山寨版

看了《玩转FPGA》,写的不错,写写山寨版和大家交流!

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

基于FPGA串口通信DMA实验

使用软件 :Quartus II 9.0 和 Nios II IDE 9.0

开发板    : Altera DE2

实验内容 :UART (RS232)发送数据通过DMA接受,传到SDRAM中,我们可以通过JTAG UART 在 Nios II IDE 的Debug中看到SDRAM的数据

 

一、硬件设计

1、创建Quartus II工程

在Quartus II 左上面点击New菜单,选择第一项New Quartus II Project

建立UART_DMA工程

2、创建SOPC系统

(1) Nios II CPU core

(2) 添加PLL

 

输入clock 选择50MHz

C0  :  50MHz  相位为0  , 为系统提供clk ,更为为sys_clk

C1 :  50MHz  相位为-75度,为SDRAM提供clk,更为DRAM_CLK

(3) 添加SDRAM,数据位选择16位

(4)添加tri_state_bridge 和CFI flash

(5)添加SRAM,IP为友晶公司提供

(6)添加UART(RS232)

(7)添加JTAG UART

(8)添加DMA

DMA的read master接到UART,write master接到SDRAM

 

(9)添加sysid

SDRAM的地址等会Dubeg中要用

3、创建BDF,添加刚才新建的SOPC,修改引脚

新建tcl脚本锁定引脚

**********************************************************************

set_global_assignment -name RESERVE_ALL_UNUSED_PINS "AS INPUT TRI-STATED"
set_global_assignment -name ENABLE_INIT_DONE_OUTPUT OFF

#RS232
set_location_assignment PIN_C25  -to UART_RXD
set_location_assignment PIN_B25  -to UART_TXD

#SDRAM
set_location_assignment PIN_T6  -to DRAM_ADDR[0]
set_location_assignment PIN_V4  -to DRAM_ADDR[1]
set_location_assignment PIN_V3  -to DRAM_ADDR[2]
set_location_assignment PIN_W2  -to DRAM_ADDR[3]
set_location_assignment PIN_W1  -to DRAM_ADDR[4]
set_location_assignment PIN_U6  -to DRAM_ADDR[5]
set_location_assignment PIN_U7  -to DRAM_ADDR[6]
set_location_assignment PIN_U5  -to DRAM_ADDR[7]
set_location_assignment PIN_W4  -to DRAM_ADDR[8]
set_location_assignment PIN_W3  -to DRAM_ADDR[9]
set_location_assignment PIN_Y1  -to DRAM_ADDR[10]
set_location_assignment PIN_V5  -to DRAM_ADDR[11]

set_location_assignment PIN_V6  -to DRAM_DQ[0]
set_location_assignment PIN_AA2  -to DRAM_DQ[1]
set_location_assignment PIN_AA1  -to DRAM_DQ[2]
set_location_assignment PIN_Y3  -to DRAM_DQ[3]
set_location_assignment PIN_Y4  -to DRAM_DQ[4]
set_location_assignment PIN_R8  -to DRAM_DQ[5]
set_location_assignment PIN_T8  -to DRAM_DQ[6]
set_location_assignment PIN_V7  -to DRAM_DQ[7]
set_location_assignment PIN_W6  -to DRAM_DQ[8]
set_location_assignment PIN_AB2  -to DRAM_DQ[9]
set_location_assignment PIN_AB1  -to DRAM_DQ[10]
set_location_assignment PIN_AA4  -to DRAM_DQ[11]
set_location_assignment PIN_AA3  -to DRAM_DQ[12]
set_location_assignment PIN_AC2  -to DRAM_DQ[13]
set_location_assignment PIN_AC1  -to DRAM_DQ[14]
set_location_assignment PIN_AA5  -to DRAM_DQ[15]

set_location_assignment PIN_AE2  -to DRAM_BA[0]
set_location_assignment PIN_AE3  -to DRAM_BA[1]

set_location_assignment PIN_AD2  -to DRAM_DQM[0]
set_location_assignment PIN_Y5  -to DRAM_DQM[1]

set_location_assignment PIN_AA6  -to DRAM_CKE
set_location_assignment PIN_AA7  -to DRAM_CLK
set_location_assignment PIN_AD3  -to DRAM_WE_N
set_location_assignment PIN_AC3  -to DRAM_CS_N
set_location_assignment PIN_AB3  -to DRAM_CAS_N
set_location_assignment PIN_AB4  -to DRAM_RAS_N

#FLASH
set_location_assignment PIN_AC18 -to FL_ADDR[0]
set_location_assignment PIN_AB18 -to FL_ADDR[1]
set_location_assignment PIN_AE19 -to FL_ADDR[2]
set_location_assignment PIN_AF19 -to FL_ADDR[3]
set_location_assignment PIN_AE18 -to FL_ADDR[4]
set_location_assignment PIN_AF18 -to FL_ADDR[5]
set_location_assignment PIN_Y16  -to FL_ADDR[6]
set_location_assignment PIN_AA16 -to FL_ADDR[7]
set_location_assignment PIN_AD17 -to FL_ADDR[8]
set_location_assignment PIN_AC17 -to FL_ADDR[9]
set_location_assignment PIN_AE17 -to FL_ADDR[10]
set_location_assignment PIN_AF17 -to FL_ADDR[11]
set_location_assignment PIN_W16  -to FL_ADDR[12]
set_location_assignment PIN_W15  -to FL_ADDR[13]
set_location_assignment PIN_AC16 -to FL_ADDR[14]
set_location_assignment PIN_AD16 -to FL_ADDR[15]
set_location_assignment PIN_AE16 -to FL_ADDR[16]
set_location_assignment PIN_AC15 -to FL_ADDR[17]
set_location_assignment PIN_AB15 -to FL_ADDR[18]
set_location_assignment PIN_AA15 -to FL_ADDR[19]
set_location_assignment PIN_Y15  -to FL_ADDR[20]
set_location_assignment PIN_Y14  -to FL_ADDR[21]
set_location_assignment PIN_V17  -to FL_CE_N
set_location_assignment PIN_W17  -to FL_OE_N
set_location_assignment PIN_AD19 -to FL_DQ[0]
set_location_assignment PIN_AC19 -to FL_DQ[1]
set_location_assignment PIN_AF20 -to FL_DQ[2]
set_location_assignment PIN_AE20 -to FL_DQ[3]
set_location_assignment PIN_AB20 -to FL_DQ[4]
set_location_assignment PIN_AC20 -to FL_DQ[5]
set_location_assignment PIN_AF21 -to FL_DQ[6]
set_location_assignment PIN_AE21 -to FL_DQ[7]
set_location_assignment PIN_AA18 -to FL_RST_N
set_location_assignment PIN_AA17 -to FL_WE_N

set_location_assignment PIN_N2  -to CLOCK_50

#SRAM
set_location_assignment PIN_AE4  -to SRAM_ADDR[0]
set_location_assignment PIN_AF4  -to SRAM_ADDR[1]
set_location_assignment PIN_AC5  -to SRAM_ADDR[2]
set_location_assignment PIN_AC6  -to SRAM_ADDR[3]
set_location_assignment PIN_AD4  -to SRAM_ADDR[4]
set_location_assignment PIN_AD5  -to SRAM_ADDR[5]
set_location_assignment PIN_AE5  -to SRAM_ADDR[6]
set_location_assignment PIN_AF5  -to SRAM_ADDR[7]
set_location_assignment PIN_AD6  -to SRAM_ADDR[8]
set_location_assignment PIN_AD7  -to SRAM_ADDR[9]
set_location_assignment PIN_V10  -to SRAM_ADDR[10]
set_location_assignment PIN_V9  -to SRAM_ADDR[11]
set_location_assignment PIN_AC7  -to SRAM_ADDR[12]
set_location_assignment PIN_W8  -to SRAM_ADDR[13]
set_location_assignment PIN_W10  -to SRAM_ADDR[14]
set_location_assignment PIN_Y10  -to SRAM_ADDR[15]
set_location_assignment PIN_AB8  -to SRAM_ADDR[16]
set_location_assignment PIN_AC8  -to SRAM_ADDR[17]

set_location_assignment PIN_AD8  -to SRAM_DQ[0]
set_location_assignment PIN_AE6  -to SRAM_DQ[1]
set_location_assignment PIN_AF6  -to SRAM_DQ[2]
set_location_assignment PIN_AA9  -to SRAM_DQ[3]
set_location_assignment PIN_AA10 -to SRAM_DQ[4]
set_location_assignment PIN_AB10 -to SRAM_DQ[5]
set_location_assignment PIN_AA11 -to SRAM_DQ[6]
set_location_assignment PIN_Y11  -to SRAM_DQ[7]
set_location_assignment PIN_AE7  -to SRAM_DQ[8]
set_location_assignment PIN_AF7  -to SRAM_DQ[9]
set_location_assignment PIN_AE8  -to SRAM_DQ[10]
set_location_assignment PIN_AF8  -to SRAM_DQ[11]
set_location_assignment PIN_W11  -to SRAM_DQ[12]
set_location_assignment PIN_W12  -to SRAM_DQ[13]
set_location_assignment PIN_AC9  -to SRAM_DQ[14]
set_location_assignment PIN_AC10 -to SRAM_DQ[15]

set_location_assignment PIN_AE10 -to SRAM_WE_N
set_location_assignment PIN_AD10 -to SRAM_OE_N
set_location_assignment PIN_AF9  -to SRAM_UB_N
set_location_assignment PIN_AE9  -to SRAM_LB_N
set_location_assignment PIN_AC11 -to SRAM_CE_N

************************************************************************************

 

 注意:flash的FL_RST_N 拉为高电平

 

二、软件

打开Nios II IDE,新建工程

******************************************************************************************

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "system.h"
#include "sys/alt_dma.h"

int main(void)
{
    alt_dma_rxchan rx;
    //创建DMA接收信道
    rx = alt_dma_rxchan_open("/dev/dma");
    //当信道创建成功
    if(rx != NULL)
    {
        printf("Dma transition start.");
        while(1)
        {
            //设置DMA传输的数据位宽为8位
            alt_dma_rxchan_ioctl(rx,ALT_DMA_SET_MODE_8,NULL);
            //指定从uart接收数据
            alt_dma_rxchan_ioctl(rx,ALT_DMA_RX_ONLY_ON,(void*)UART_BASE);
           
            //提交DMA接收请求 指定接收数据的位置(sdram)以及传输数据量
            if( alt_dma_rxchan_prepare(rx,(void*)SDRAM_BASE, 1024,  NULL, NULL)  < 0 )
            {
                printf ("Error: failed to post receive request\n");
            }
            //关闭DMA接收信道
            alt_dma_rxchan_close(rx);
            usleep(1000000);
        }
    }
    return 0;
}

******************************************************************************************

System Library配置为:

 

 

 

三、打开串口助手

四、Debug as Nios hardware

在下方调试栏Memory里新添SDRAM的基地址

posted on 2010-09-25 10:15  Neddy11  阅读(5514)  评论(1)    收藏  举报