Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Easy nios II design

Altera_Forum
Honored Contributor II
949 Views

Hello, 

 

I am a newbie with Quartus II and Nios II and I have been trying to do an easy nios design in order to light on a led when pressing a button. I am working on the Altera Cyclone III EP3C25F324 board. I think the problem comes from my code in nios II that I put below. I don't really know when to write "IOWR_ALTERA_AVALON_PIO_DATA(...);" maybe the problem comes from here. Plus, when I try to write some "printf", there is an error : 

 

collect2: ld returned 1 exit status 

make: *** [button_led.elf] Error 1 

 

 

Here is my program : 

# include "system.h"# include "altera_avalon_pio_regs.h"# include "alt_types.h"# include "stdio.h"# include "stdlib.h" 

 

int alt_main (void) 

alt_u8 led = 0x2; 

alt_u8 button = 0x2; 

 

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led); 

IOWR_ALTERA_AVALON_PIO_DATA(BUTTON_PIO_BASE, button); 

 

while (1) 

switch (button) { 

 

case 0x1 : 

led=0x1; 

break; 

 

case 0x2 : 

led=0x2; 

break; 

 

case 0x4 : 

led=0x4; 

break; 

 

case 0x8 : 

led=0x8; 

break; 

 

Do someone can help me? 

Thank you very much, 

 

Myriam
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
328 Views

Hi Myriam, 

 

Without getting into a discussion about better ways of handling buttons, here are some changes that should get your code doing what you expected it to do: 

# include "system.h"# include "altera_avalon_pio_regs.h"# include "alt_types.h"# include "stdio.h"# include "stdlib.h" 

 

int alt_main (void) 

alt_u8 led; 

alt_u8 button; 

 

while (1) 

button = IORD_ALTERA_AVALON_PIO_DATA(BUTTON_PIO_BASE); 

 

switch (button) { 

 

case 0x1 : 

led=0x1; 

break; 

 

case 0x2 : 

led=0x2; 

break; 

 

case 0x4 : 

led=0x4; 

break; 

 

case 0x8 : 

led=0x8; 

break; 

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led); 

 

 

 

Note that the button PIO is read with an IORD_ function call. 

 

I imagine your problem with printf is that you do not have a device configured for stdout. 

 

0 Kudos
Reply