Nios 2 "Hello World"? - c

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. With the Nios 2 IDE I can download the project to the DE2 FPGA and the clock runs as expected. 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.
The Hello World example is just
/*
* "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? 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?
Update
It's not working at all. I tried the different combinations in the BSP editor and none work. 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. 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.
This implementation uses Altera Quartus, Nios II and the SOPC Builder. I'll try to summarize the steps below:
You would need to write SRAM and LED controllers in VHDL/Verilog to connect to the Avalon Bus. Create a system on the SOPC Builder. Use these controllers to create components in the SOPC Builder (SRAM and LED components).
Connect the components to the Nios II processor, and the JTAG debug module. Assign base addresses and generate your system.
In Nios II, create a C project (Nios II Application and BSP from template) using the SOPC file generated by the SOPC Builder.
Replace the code in the template with a C Program (in this case an LED flasher program). Access the LEDs using the base addresses you generated earlier.
Build and run your program as Nios II Hardware.
More info here.

The program IS running on the board. From the program comments...
This example prints 'Hello from Nios II' to the STDOUT stream.
The STDOUT stream in this case is the software terminal. So the Nios II board is running the hello world program and sending the output to the computer. 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.

From the Nios II documentation (Nios II Software Developer’s Handbook), you have to update your BSP to set stdout as the correct device.
Example:
nios2-bsp hal my_bsp --default_stdio uart1

Probably you didn't understood the flow about how its working, basically
You have to include JTAG-UART module to all your NIOS II System. which is a combination of CPU Debugger and UART communication for the system.
Whenever you use pritnf or scanf statements, there is no standard IO in the hardware. so the system will use JTAG- UART peripheral to communicate with IDE.
The same USB cable is used for downloading as well as JTAG UART
Actually the program is downloading in the hardware and using the USB cable connected with the Kit, printing in the console.
if user wish to change it, do it in BSP Editor but with respective IP added in the system.

Related

niosii processor Altera C program

I'm currently working on the Altera DE0 board with the QuartusII Web Edition software. I need to use a nios processor on Qsys to display a shifted signal from a GPIO pin on my board. The input signal would be a clock signal from an external source. The problem is that I have no idea how I can write a program in C (on the Eclipse IDE) for diplaying a delayed clock on an oscilloscope.
My Qsys design looks like that Image1 => Qsys Design and here the Eclipse IDE where I have to write my C program Image2 => Eclipse IDE
Please help me !
thank you very much in advance for the replies
start with the system.h file to know which base_address is assigned to each peripherial, then you can use pointers to directly access the GPIO or use the IORD/IOWR functions.

parallella fpga : how to give an interrupt from pl to arm ps

I successfully implemented an "[accelerator in 15 minutes]"1 on parallella board. Now I need to send an interrupt from pl to ps. So I connected it to IRQ_F2P of Zynq processing system.
Now, how can I get this interrupt in arm processor?
Usual interrupt example using "XILINX SDK" tool which uses a JTAG. But in parallella , I don't have a JTAG. (I am coping the program to SD card and execute it from SD card using Ubuntu). So any suggestions are most welcome.
So for parallella, I tried to use the Xilinx SDK, but the header files are creating an error..
My one more doubt is "Is it possible to create a bsp using sdk tool and copy it into sd card and then make it run on parallella board. Will it work ?
If not, how do we get this interrupt in arm processor, because all example uses Xilinx header files like "xparameters.h, xil_printf.h, xcugic.h, etc" and these are connected to many other Xilinx functions.

Arduino code Wire ported to Atmel Xplained Mini to communicate with DS3231

I am taking Arduino Prototype code used for a DS3231 RTC and taking it to an embedded platform that does not directly support Arduino code (right now that is the Atmel Xplained Mini). Is there a way for me to create an equivalent program without writing an entire I2C protocol and the entire data communication from scratch? There must be an overlapping library/header/code block that I can adapt to my purpose.
As an example I am looking to make the code here work on the Atmel Xplained Board. The code should be pretty simple, what I need is for the DS3231 to tell the MCU the time when it asks for it. I can do the manipulation of the date/time myself, it is getting that information on a non-Arduino platform that is the road block for me.
Arduino has an existing wiring library that facilitates I2C communication, most professional development frameworks aren't quite so simple but are also more full-featured. I'm assuming you are using Atmel Studio, you'll want to look at the TWI (two-wire interface) documentation for doing I2C communication.
AVR315: Using the TWI Module as I2C Master
You can copy TWI_Master.c and TWI_Master.h to your project and use these for I2C communication. That is what I've typically done in the past.
The demo code that goes with this app note can be found here, main.c has an example of the usage of this I2C driver:
AVR315 Demo Code

Communication with mbed using C

How can I communicate with an mbed LPC1768 using C without using a terminal emulator like minicom or teraterm?
For example if I send an integer from my C code than that led should be turned on.
How can I do this?
Without reading user manual or datasheet you can't do any thing to your board. So just go through it then follow below link for demo application LPC1768 board
1.NXP LPC1768 ARM Cortex-M3 Red Suite Demo
2.LPC1768 ARM Cortex-M3 CrossWorks Demo
3.mbed
4.At github
If you are using linux or osx check out the following answer:
How do I read data from serial port in Linux using C?
You can check your /dev folder and look for a file that is created when you plug your mBed. The file name would be something like /dev/ttyS0. That file represents the communication port, you can read/write that file to receive/send data over serial port.
If you want a cross platform solution try RxTx library for Java.
You can use this library
what it does, is that it initialize UART port which is connected to the debugger on your board and use it as serial input output. so with any hyper terminal of your choice, you can write code to do something if you send certain string of characters or just use original printf when something happens. and it will be printed on your PC screen.

How to run this code as Nios hardware?

I got a Nios 2 project that is supposed to be able to run as hardware on my FPGA but how?
I've built it and I can run it in the simulator:
I've chose the uart0 in the BSP editor
But then when I run it as Nios hardware nothing happens
Can you tell me how it should be done?
It works to load the FPGA with a system in Quartus II programmer:
Update
The instructor has answered.
It's possible to run the OS on the DE2 board but the program will
execute quickly. The > output comes on the serial port uart0, i.e.
the 9-polar D-sub contact. Since the program is running so quickly
it can be wise to disconnect the USB-to-serial > adapter from the DE2
(but not from the PC) when the number 2333 has been consumed. >
Otherwise the buffer in putty will be full so that the output from the
beginning of the run is lost.
I've read your other thread, about Hello World on Nios II and nowhere do you mention that you configure the FPGA for running the NIOS II, so maybe that's the problem?
I quote from Nios II handbook (see page 2-5 and 2-6):
"Configuring the FPGA.
Before you can run your software, you must ensure that the correct hardware design is running on the FPGA. To configure the FPGA, you use the Quartus® II Programmer.
In the Windows operating system, you start the Quartus II Programmer from the Nios II SBT for Eclipse, through the Nios II menu. In the Linux operating system, you start Quartus II Programmer from the Quartus II software.
The project directory for your hardware design contains an SRAM Object File (.sof)
along with the .sopcinfo file. The .sof file contains the hardware design to be programmed in the FPGA."
Also se the Qartus II FPGA programmer handbook for info on how to program your FPGA.

Resources