superstar_gu 发表于 2021-4-19 10:31

【Perf-V评测】基于Perf-V开发板蜂鸟定时器中断开发

<p>彭峰科技为Perf-V开发板提供蜂鸟E203软核。开发者可以方便地应用RISC-V指令集进行编程应用。本文将尝试基于蜂鸟E203软核进行编程。<br />
&nbsp;<br />
由于有了蜂鸟E203软核,Perf-V开发板开发变换到Hbird-B-SDK平台,它地结构如下:<br />
&nbsp;<br />
我们后面应用下列三个头文件:<br />
#include &quot;platform.h&quot;定义了SoC平台相关宏定义<br />
#include &quot;encoding.h&quot;存放编码和常数地宏定义<br />
#include &quot;plic/plic_driver.h&quot;存放驱动代码定义<br />
我们基于彭峰科技三色LED闪烁程序,设计新的定时器中断程序;<br />
1.&nbsp;&nbsp; &nbsp;设计需求<br />
(1)&nbsp;&nbsp; &nbsp;D0每隔1s亮灭循环<br />
(2)&nbsp;&nbsp; &nbsp;利用定时器中断<br />
2.&nbsp;&nbsp; &nbsp;硬件原理图如下所示:<br />
&nbsp;<br />
&nbsp;<br />
通过查询VIVADO工程文件,找出E203软核与FPGA引脚相关映射关系如下表所示:<br />
名称&nbsp;&nbsp; &nbsp;方向&nbsp;&nbsp; &nbsp;GPGA pin&nbsp;&nbsp; &nbsp;IO标准&nbsp;&nbsp; &nbsp;E203名称<br />
led_0&nbsp;&nbsp; &nbsp;OUTPUT&nbsp;&nbsp; &nbsp;P6&nbsp;&nbsp; &nbsp;LVCMOS33&nbsp;&nbsp; &nbsp;<br />
led_1&nbsp;&nbsp; &nbsp;OUTPUT&nbsp;&nbsp; &nbsp;K12&nbsp;&nbsp; &nbsp;LVCMOS33&nbsp;&nbsp; &nbsp;<br />
led_2&nbsp;&nbsp; &nbsp;OUTPUT&nbsp;&nbsp; &nbsp;M16&nbsp;&nbsp; &nbsp;LVCMOS33&nbsp;&nbsp; &nbsp;<br />
led_3&nbsp;&nbsp; &nbsp;OUTPUT&nbsp;&nbsp; &nbsp;P16&nbsp;&nbsp; &nbsp;LVCMOS33&nbsp;&nbsp; &nbsp;<br />
sw_0&nbsp;&nbsp; &nbsp;INOUT&nbsp;&nbsp; &nbsp;T15&nbsp;&nbsp; &nbsp;LVCMOS33&nbsp;&nbsp; &nbsp;</p>

<p>3.&nbsp;&nbsp; &nbsp;工程创建<br />
在software下创建&ldquo;test1_gpio&rdquo;文件夹,新建test1_gpio.c文件,代码如下所示:<br />
// These buttons are present only on the Freedom E300 Arty Dev Kit.<br />
#ifdef HAS_BOARD_BUTTONS<br />
#define BUTTON_0_OFFSET 15<br />
#define BUTTON_1_OFFSET 30<br />
#define BUTTON_2_OFFSET 31</p>

<p>#define INT_DEVICE_BUTTON_0 (INT_GPIO_BASE + BUTTON_0_OFFSET)<br />
#define INT_DEVICE_BUTTON_1 (INT_GPIO_BASE + BUTTON_1_OFFSET)<br />
#define INT_DEVICE_BUTTON_2 (INT_GPIO_BASE + BUTTON_2_OFFSET)<br />
&nbsp;<br />
//Perf-V 引脚定义列表<br />
//三色led引脚定义<br />
#define&nbsp;&nbsp; &nbsp;led0_r&nbsp;&nbsp; &nbsp;PIN_1_OFFSET<br />
#define&nbsp;&nbsp; &nbsp;led0_g&nbsp;&nbsp; &nbsp;PIN_2_OFFSET<br />
#define&nbsp;&nbsp; &nbsp;led0_b&nbsp;&nbsp; &nbsp;PIN_3_OFFSET</p>

<p>#define&nbsp;&nbsp; &nbsp;led1_r&nbsp;&nbsp; &nbsp;PIN_19_OFFSET<br />
//#define&nbsp;&nbsp; &nbsp;led1_g&nbsp;&nbsp; &nbsp;PIN_21_OFFSET<br />
//#define&nbsp;&nbsp; &nbsp;led1_b&nbsp;&nbsp; &nbsp;PIN_22_OFFSET</p>

<p>#define&nbsp;&nbsp; &nbsp;led2_r&nbsp;&nbsp; &nbsp;PIN_11_OFFSET<br />
#define&nbsp;&nbsp; &nbsp;led2_g&nbsp;&nbsp; &nbsp;PIN_12_OFFSET<br />
#define&nbsp;&nbsp; &nbsp;led2_b&nbsp;&nbsp; &nbsp;PIN_13_OFFSET</p>

<p>#define&nbsp;&nbsp; &nbsp;btn_0&nbsp;&nbsp; &nbsp;PIN_15_OFFSET<br />
//#define&nbsp;&nbsp; &nbsp;btn_1 &nbsp; PIN_30_OFFSET<br />
//#define&nbsp;&nbsp; &nbsp;btn_2 &nbsp; PIN_31_OFFSET<br />
&nbsp;</p>

<p>//SPI2 pins<br />
//#define&nbsp;&nbsp; &nbsp;ck_ss &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;PIN_26_OFFSET&nbsp;&nbsp; &nbsp;<br />
//#define&nbsp;&nbsp; &nbsp;ck_mosi &nbsp; &nbsp; PIN_27_OFFSET<br />
//#define&nbsp;&nbsp; &nbsp;ck_miso&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;PIN_28_OFFSET<br />
//#define&nbsp;&nbsp; &nbsp;ck_sck &nbsp; &nbsp; &nbsp;PIN_29_OFFSET<br />
//led<br />
#define&nbsp;&nbsp; &nbsp;led_0<br />
#define&nbsp;&nbsp; &nbsp;led_1<br />
#define&nbsp;&nbsp; &nbsp;led_2<br />
#define&nbsp;&nbsp; &nbsp;led_3&nbsp;&nbsp; &nbsp;PIN_14_OFFSET<br />
<br />
4.&nbsp;&nbsp; &nbsp;编写makefile文件</p>

<p>编写makefile文件,目标文件定义为test1_g,指定头文件地址和源程序,代码如下所示:<br />
&ldquo;make software PROGRAM=demo_gpio BOARD=Perf-V-creative-board&rdquo;<br />
5.&nbsp;&nbsp; &nbsp;下载</p>

<p>&nbsp;下载并测试</p>

火辣西米秀 发表于 2021-4-20 17:26

<p>VIVADO工程文件在哪里查的呢</p>
页: [1]
查看完整版本: 【Perf-V评测】基于Perf-V开发板蜂鸟定时器中断开发