简体   繁体   English

Nios 2“Hello World”?

[英]Nios 2 “Hello World”?

I've managed to run a complicated project on the Nios 2 Altera DE2 board where I created a timer with assembly and C code using the input and output. 我已经设法在Nios 2 Altera DE2板上运行一个复杂的项目,在那里我使用输入和输出创建了一个带有汇编和C代码的定时器。 With the Nios 2 IDE I can download the project to the DE2 FPGA and the clock runs as expected. 使用Nios 2 IDE,我可以将项目下载到DE2 FPGA,时钟按预期运行。 But I don't understanding everything about the programming model and I'm also trying to understand the basic Hello World example and the diagnostics example that comes with the IDE. 但我不了解编程模型的所有内容,我也试图理解基本的Hello World示例和IDE附带的诊断示例。

The Hello World example is just Hello World的例子就是

/*
 * "Hello World" example.
 *
 * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
 * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example
 * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT
 * device in your system's hardware.
 * The memory footprint of this hosted application is ~69 kbytes by default
 * using the standard reference design.
 *
 * For a reduced footprint version of this template, and an explanation of how
 * to reduce the memory footprint for a given application, see the
 * "small_hello_world" template.
 *
 */

#include <stdio.h>

int main()
{
  printf("Hello from Nios II!\n");

  return 0;
}

But when I compile and run this "as Nios 2 hardware", it only prints Hello World to the standard out in the IDE, it does not download and run on the board - isn't is supposed to do that? 但是当我编译并运行“作为Nios 2硬件”时,它只会在IDE中打印Hello World到标准,它不会下载并在板上运行 - 不应该这样做吗? What is the point of the example if it does't run on the board? 如果它不在板上运行,那么示例的重点是什么? Did I do anything wrong, if so what since the example compiles and runs? 我做错了什么,如果是这样,那么自编译和运行以来该怎么办? Do I have to set the BSD editor to something? 我是否必须将BSD编辑器设置为某些内容?

Update 更新

It's not working at all. 它根本不起作用。 I tried the different combinations in the BSP editor and none work. 我尝试了BSP编辑器中的不同组合,但都没有。 When I try to run the project as "Nios II hardware" nothing happens on the board even though it says in the IDE that the project is downloading to the board. 当我尝试将项目作为“Nios II硬件”运行时,即使它在IDE中说项目正在下载到电路板上,也没有任何事情发生在电路板上。 Why is the easy thing difficult? 为什么这件事很难? The UX is horrible and having to guess is not scientific. 用户体验非常糟糕,不得不猜测是不科学的。

在此输入图像描述

Here's a link from an Embedded Systems Design Course in Columbia University. 这是哥伦比亚大学嵌入式系统设计课程的链接

Check the link to lab 3 for an implementation of flashing LEDs with VHDL and C on the Altera DE2 Board. 检查实验3链接,了解Altera DE2板上带有VHDL和C的闪烁LED的实现。

This implementation uses Altera Quartus, Nios II and the SOPC Builder. 该实现使用Altera Quartus,Nios II和SOPC Builder。 I'll try to summarize the steps below: 我将尝试总结以下步骤:

  1. You would need to write SRAM and LED controllers in VHDL/Verilog to connect to the Avalon Bus. 您需要在VHDL / Verilog中编写SRAM和LED控制器以连接到Avalon总线。 Create a system on the SOPC Builder. 在SOPC Builder上创建一个系统。 Use these controllers to create components in the SOPC Builder (SRAM and LED components). 使用这些控制器在SOPC Builder(SRAM和LED组件)中创建组件。

  2. Connect the components to the Nios II processor, and the JTAG debug module. 将组件连接到Nios II处理器和JTAG调试模块。 Assign base addresses and generate your system. 分配基地址并生成系统。

  3. In Nios II, create a C project (Nios II Application and BSP from template) using the SOPC file generated by the SOPC Builder. 在Nios II中,使用SOPC Builder生成的SOPC文件创建一个C项目(Nios II Application和BSP from template)。

  4. Replace the code in the template with a C Program (in this case an LED flasher program). 用C程序替换模板中的代码(在本例中为LED闪光灯程序)。 Access the LEDs using the base addresses you generated earlier. 使用先前生成的基址访问LED。

  5. Build and run your program as Nios II Hardware. 以Nios II硬件构建并运行您的程序。

More info here . 更多信息在这里

From the Nios II documentation ( Nios II Software Developer's Handbook ), you have to update your BSP to set stdout as the correct device. 从Nios II文档( Nios II软件开发人员手册 )中,您必须更新BSP以将stdout设置为正确的设备。

Example: 例:

nios2-bsp hal my_bsp --default_stdio uart1

The program IS running on the board. 程序IS在板上运行。 From the program comments... 从节目评论......

This example prints 'Hello from Nios II' to the STDOUT stream. 此示例将'Hello from Nios II'打印到STDOUT流。

The STDOUT stream in this case is the software terminal. 在这种情况下,STDOUT流是软件终端。 So the Nios II board is running the hello world program and sending the output to the computer. 所以Nios II板正在运行hello world程序并将输出发送到计算机。 To use the screen on the board you'll have to include the LCD display in the configuration with the SOPC builder, then write to the LCD screen directly. 要使用电路板上的屏幕,您必须在配置中使用SOPC构建器包含LCD显示器,然后直接写入LCD屏幕。

Probably you didn't understood the flow about how its working, basically 可能你基本上没有理解它的工作方式

  1. You have to include JTAG-UART module to all your NIOS II System. 您必须在所有NIOS II系统中包含JTAG-UART模块。 which is a combination of CPU Debugger and UART communication for the system. 这是系统的CPU调试器和UART通信的组合。
  2. Whenever you use pritnf or scanf statements, there is no standard IO in the hardware. 无论何时使用pritnf或scanf语句,硬件中都没有标准IO。 so the system will use JTAG- UART peripheral to communicate with IDE. 因此系统将使用JTAG-UART外设与IDE通信。
  3. The same USB cable is used for downloading as well as JTAG UART 使用相同的USB电缆进行下载以及JTAG UART

Actually the program is downloading in the hardware and using the USB cable connected with the Kit, printing in the console. 实际上程序是在硬件中下载并使用与套件连接的USB电缆,在控制台中打印。

if user wish to change it, do it in BSP Editor but with respective IP added in the system. 如果用户希望更改它,请在BSP编辑器中执行此操作,但在系统中添加了相应的IP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM