Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

How to implement very basic custom QSys component

I know this question has to have been posted and answered, but I can't find it in a way I can understand and solve my problem.

My effort is very basic and I'm new to the QSys way of FPGAs. Basically, I'm attempting to flash the LEDs of a De0 Nano from 'C'.

I've divided the 8 LEDs into 3.

Led7 is a VHDL heartbeat

Led6..4 is a software controlled LED set via the standard altera Qsys PIO.

Led3..0 a software controlled LED set via a custom avalon slave VHDL Qsys module

Every thing compiles and programs fine.

Led7, the heartbeat, is working fine.

Led6..4 is working fine.

Led3..0, my custom Qsys component, is not working.

What have I done wrong? What am I missing?

I've added the following VHDL component.

ENTITY LGLed IS

PORT(

clk : in std_logic;

reset_n : in std_logic;

write : in std_logic;

writedata : in std_logic_vector(7 downto 0);

leds : out std_logic_vector(3 downto 0)

 );

END LGLed;

-- Architecture Body

ARCHITECTURE synth OF LGLed IS

signal myleds : std_logic_vector(3 downto 0);

BEGIN

process(clk, reset_n)

begin

if(reset_n = '0')then

myleds <= to_stdlogicvector(x"0");

else

if ((write = '1') and rising_edge(clk))then

myleds <= writedata(3 downto 0);

end if;

end if;

leds <= myleds;

end process;

end synth;

My C code is as follows:

# include <stdio.h># include "sys/alt_stdio.h"# include "alt_types.h"# include "system.h"# include "altera_avalon_pio_regs.h"

# define LEDDELAY 125000

int main()

{ int n1;

int cnt=0;

unsigned char *my_register = (unsigned char*)alt_remap_uncached((void*)LGLED_BASE,sizeof(alt_8));

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

while(1) {

for (n1=0; n1 < LEDDELAY; n1++) {}

IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_GREEN_BASE, (cnt) & 0xF);

// IOWR_ALTERA_AVALON_PIO_DATA(LGLED_BASE, (cnt) & 0xF);

*my_register = (cnt) & 0xF;

cnt++;

}

return 0;

}

11 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hello,

    I am looking for interfacing a custom component with Arm processor. I have very little knowledge of Altera software tools. Could you please share document or link for learning custom component interface and use in bare metal or Linux environment? Could you please share how you learnt interfacing your custom peripheral slave?

    Thank you.