当前位置:网站首页>【SOC FPGA】外设KEY点LED
【SOC FPGA】外设KEY点LED
2022-07-30 15:39:00 【菜虚鲲001】
文章目录
一、添加LED和KEY的pio外设
1、黄金参考工程
2、配置pio外设
打开Plaform Designer,右侧搜索pio并双击。
(1)添加pio_KEY
我们使用key1和key2,所以选择2位。
连线:
(2)添加pio_LED
cyclone Ⅴ的板子有四个LED,所以选择4位。
连线:
默认给led和key分配的地址都是0,所以点击分配地址可解决报错。
3、修改Verilog代码
连线完成后点击Genrate HDL,自动实例化。
在top模块中定义接口并实例化
4、全编译
没有错误就很完美
二、生成相应的文件,转移至sd卡内
1、更新dtb文件
打开SOC…Shell
进入黄金工程目录:
make dtb
更新dtb文件
看文件时间是否更新成功
2、更新rbf文件
运行命令:
cd output_files/
./sof_to_rbf.bat
看文件时间是否更新成功
3、更新hps_0.h文件
运行:
./generate_hps_qsys_header.sh
看文件时间是否更新成功
4、替换sd卡中的内容
三、编写C代码实现功能
打开eclipse
1、C工程准备
新建一个Cproject
导入库文件:
将黄金工程的hps_0.h放入工程中
2、C语言实现按键点灯
代码实现:
/* * pio_led.c * * Created on: 2022年7月19日 * Author: 哈哈 */
//标准头文件
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
//HPS厂家提供的底层定义头文件
#define soc_cv_av //开发平台Cyclone V 系列
#include "hwlib.h"
#include "socal/socal.h"
#include "socal/hps.h"
//与用户具体的HPS 应用系统相关的硬件描述头文件
#include "hps_0.h"
#define HW_REGS_BASE (ALT_STM_OFST) //HPS外设地址段基地址
#define HW_REGS_SPAN (0x04000000) //HPS外设地址段地址空间 64MB大小
#define HW_REGS_MASK (HW_REGS_SPAN - 1) //HPS外设地址段地址掩码
static unsigned long *led_pio_virtual_base =NULL ;
static unsigned long *key_pio_virtual_base = NULL;
int led_init(int *virtual_base)
{
int fd;
void *perph_virtual_base;
//1.open打开
fd = open("/dev/mem",(O_RDWR | O_SYNC));
if(fd == -1)
{
printf("open failed..\n");
return 1;
}
//mmap 映射虚拟地址
perph_virtual_base = mmap(NULL,HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ),MAP_SHARED,fd,HW_REGS_BASE);
led_pio_virtual_base = perph_virtual_base +
(((unsigned)(ALT_LWFPGASLVS_OFST + PIO_LED_BASE))&(unsigned)(HW_REGS_MASK));
key_pio_virtual_base = perph_virtual_base +
(((unsigned)(ALT_LWFPGASLVS_OFST + PIO_KEY_BASE))&(unsigned)(HW_REGS_MASK));
*virtual_base = perph_virtual_base;
return fd;
}
int main()
{
int fd;
int i=0;
int virtual_base;
fd = led_init(&virtual_base);
while(1)
{
if(*(key_pio_virtual_base + 0) == 0x01)
{
*(led_pio_virtual_base + 0) = 0x01;
}
else if(*(key_pio_virtual_base + 0) == 0x02)
{
*(led_pio_virtual_base + 0) = 0x02;
}
/**(led_pio_virtual_base +0) = 1<<i; i=(i+1)%4; sleep(1); printf("LIGHT:%d ON\n",i);*/
}
//取消映射
if(munmap(virtual_base,HW_REGS_SPAN) == -1)
{
printf("fail\n");
}
close(fd);
return 0;
}
3、效果演示
FPGA之SOC按键点灯
边栏推荐
- yarn的安装及使用教程
- tiup env
- 【HMS core】【Media】【Video Editing Service】 The online material cannot be displayed, it is always in the loading state or the network is abnormal
- 谷歌工程师『代码补全』工具;『Transformers NLP』随书代码;FastAPI开发模板;PyTorch模型加速工具;前沿论文 | ShowMeAI资讯日报
- TiDB 工具功能概览
- Load Base Split usage documentation
- tiup install
- Store Limit usage documentation
- tiup completion
- PCIE入门
猜你喜欢
[AGC] Quality Service 2 - Performance Management Example
The Prospects of the Metaverse and the Four Tracks
数据库-SQL
PCIE下载的驱动安装
新技术要去做新价值
(Popular Science) What is Fractional NFT (Fractional NFT)
华为ADS获取转化跟踪参数报错:getInstallReferrer IOException: getInstallReferrer not found installreferrer
FME realizes the method of converting CAD with attribute to SHP data
flask获取post请求参数
动态规划 --- 状态压缩DP 详细解释
随机推荐
rhce笔记2
Core Topics under Microservice Architecture (2): Design Principles and Core Topics of Microservice Architecture
Back waves are coming!Ali produced the "second generation" container technical manual and brain map, which is too fragrant
go 学习03 基础知识变量类型
【AGC】质量服务2-性能管理示例
Changing SELECT...FROM to FROM...SELECT doesn't 'fix' SQL
tiup completion
TiDB 工具下载
Flask introductory learning tutorial
FME读写cass数据的方案及操作流程
php如何截取字符串的前几位
TiUP 简介
应用接入华为分析在应用调试模式下为何没有数据上报?
php how to query string occurrence position
[AGC] Quality Service 1 - Example of Crash Service
[flutter] What is MaterialApp and Material design
Recent learning defragmentation (24)
Shell脚本的概念
tiup help
When the vite multi-page application refreshes the page, it will not be in the current route and will return to the root route