跳转到主要内容

Vitis_ZCU102_3_Vitis 实现多核工作

judy 提交于

<font color="#FF8000">作者:bt_
原文链接: https://blog.csdn.net/botao_li/article/details/104039068
* 本文由作者授权转发,如需转载请联系作者本人</font>

具体方法与 SDK 的多核工作实现方法基本一致,详细操作可以参考 <a href="https://blog.csdn.net/botao_li/article/details/97266272">zcu102 系列文档</a>。

本文的代码工程继承 vitis_zcu102_1 文档

<strong>添加 Domain</strong>
打开 Platform Project,双击 platform.spr 文件,打开当前工程
<center><img src="http://xilinx.eetrend.com/files/2020-03/%E5%8D%9A%E5%AE%A2/100048361-93…; alt=""></center>

在打开的工程界面内选择当前 Platform Project,在右键菜单中选择 Add Domain

如下图所示,分别添加 psu_cortexa53_1、psu_cortexa53_2、psu_cortexa53_3 的 Domain。
<center><img src="http://xilinx.eetrend.com/files/2020-03/%E5%8D%9A%E5%AE%A2/100048361-93…; alt=""></center>

添加完全部 Domain 之后,在 Explorer 的工程中右键选择 Build Project。

<strong>添加 Application Project</strong>
在菜单栏选择 File > New > Application Project

在弹出窗口中选择 System Project 为同一个 hello_system
<center><img src="http://xilinx.eetrend.com/files/2020-03/%E5%8D%9A%E5%AE%A2/100048361-93…; alt=""></center>

按照 vitis_zcu102_1 文档的说明选择 Platform Project 和 psu_cortexa53_1、psu_cortexa53_2、psu_cortexa53_3,分别建立 3 个 Application,都使用 Hello World 模板。
<center><img src="http://xilinx.eetrend.com/files/2020-03/%E5%8D%9A%E5%AE%A2/100048361-93…; alt=""></center>

<strong>配置 Application 的指令空间</strong>
由于 4 个 A53 核使用访问同 1 个 DDR,因此必须将 4 个 Application 的指令空间分开,不能重叠。

双击打开 4 个 Application 的 lscript.ld 文件
<center><img src="http://xilinx.eetrend.com/files/2020-03/%E5%8D%9A%E5%AE%A2/100048361-93…; alt=""></center>

在 Available Memory Regions 中修改 psu_ddr_0_MEM_0
<center><img src="http://xilinx.eetrend.com/files/2020-03/%E5%8D%9A%E5%AE%A2/100048361-93…; alt=""></center>

4 个 Application 的修改数值如下表所示:

分配结果如下表:
<table border="1">
<thead>
<tr>
<th bgcolor="#99CCFF">单核工程</th>
<th bgcolor="#99CCFF">Base Address</th>
<th bgcolor="#99CCFF">Size</th>
</tr>
</thead>
<tbody>
<tr>
<td>a0</td>
<td>0x0</td>
<td>0x10000000</td>
</tr>
<tr>
<td>a1</td>
<td>0x10000000</td>
<td>0x10000000</td>
</tr>
<tr>
<td>a2</td>
<td>0x20000000</td>
<td>0x10000000</td>
</tr>
<tr>
<td>a3</td>
<td>0x30000000</td>
<td>0x10000000</td>
</tr>
</tbody>
</table>

编写测试代码:
a0 代码
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "sleep.h"

int main()
{
init_platform();

while (1)
{
print("Hello a0\n\r");
sleep(4);
}

cleanup_platform();
return 0;
}

a1 代码
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "sleep.h"

int main()
{
init_platform();

sleep(1);
while (1)
{
print("Hello a1\n\r");
sleep(4);
}

cleanup_platform();
return 0;
}

a2 代码
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "sleep.h"

int main()
{
init_platform();

sleep(2);
while (1)
{
print("Hello a2\n\r");
sleep(4);
}

cleanup_platform();
return 0;
}

a3 代码
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "sleep.h"

int main()
{
init_platform();

sleep(3);
while (1)
{
print("Hello a3\n\r");
sleep(4);
}

cleanup_platform();
return 0;
}

<strong>测试运行</strong>
在 System Project: hello_system 上右键选择 Build Project
<center><img src="http://xilinx.eetrend.com/files/2020-03/%E5%8D%9A%E5%AE%A2/100048361-93…; alt=""></center>

完成后右键选择 Run As > Run Configurations

在弹出窗口的左上角点击 New Configurations 按钮,添加新的运行配置
<center><img src="http://xilinx.eetrend.com/files/2020-03/%E5%8D%9A%E5%AE%A2/100048361-93…; alt=""></center>

在添加的运行配置的 Target Setup 页,可以看到默认配置
<center><img src="http://xilinx.eetrend.com/files/2020-03/%E5%8D%9A%E5%AE%A2/100048361-93…; alt=""></center>

zcu102 板卡上电后,点击上图中右下解的 Run 按钮

程序启动后在 Vitis Serial Terminal 中可以收到分别来源于 4 个 a53 核的字符串:
<center><img src="http://xilinx.eetrend.com/files/2020-03/%E5%8D%9A%E5%AE%A2/100048361-93…; alt=""></center>

<strong>SD 卡加载镜像</strong>
在 Vitis 菜单选择 Xilinx > Create Boot Image

<p>使用与 <a href="https://blog.csdn.net/botao_li/article/details/97266272">SDK 相同的办法</a>生成镜像文件(由于 Platform Project 已默认添加了 FSBL 和 PMU 工程,此处不用再单独添加)</p>

<center><img src="http://xilinx.eetrend.com/files/2020-03/%E5%8D%9A%E5%AE%A2/100048361-93…; alt=""></center>

生成的镜像文件 BOOT.bin 考入 SD 卡。将 zcu102 开发板设置为 SD 卡加载后,上电运行与之前的 JTag 加载运行效果一样。