LED Blinking on HPS

Hi There…

I am trying to use the example

So far, I am able to compile and run the program on the ATLAS SOC board, but the LEDs do not blink. I have a couple of questions:

  1. Is the HPS able to drive the LEDs directly or do I need to set up the FPGA to do that using Qsys?

  2. The offset ALT_STM_OFST = -67108864…does that sound right? I was surprised to see a negative number. This might be something silly I am doing just to print it.

      int aso = ALT_STM_OFST;

    int HRB = HW_REGS_BASE;
    int HRS = HW_REGS_SPAN;
    int HRM = HW_REGS_MASK;
    //n=sprintf (buffer, “%d plus %d is %d”, a, b, a+b);
    m=sprintf (buffer_m, "ALT_STM_OFST %d \nHW_REGS_BASE %d \n ", aso, HRB);

  3. The lines

    virtual_base = mmap( NULL, HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, HW_REGS_BASE );

    //m = sprintf(buffer_m, “virtualbase %s”,virtual_base);
    //printf("%s\r\n", buffer_m);
    if( virtual_base == MAP_FAILED ) {
    printf( “ERROR: mmap() failed…\n” );
    close( fd );
    return( 1 );

are meant to catch an error, but if I try to print out the variable virtual_base it is of the type void * so I wasn’t successful. The fact that it is that type made me wonder if it is working properly though. So the question is is there a better way to determine in the program if this step has worked?

Thank so much,

According to the Terasic website, the Atlas SoC has 8 LEDs on the FPGA and one on the HPS.
You can get more information and the schematic from their website.
To control the LEDs you would use QSYS to design a PIO in the FPGA.

There’s an excellent video on doing exactly this here: https://www.youtube.com/watch?v=T9VbBI3foGQ

ALT_STM_OFFSET is 0xFC000000. This is a memory address expressed in hex. If you treat this as a signed 32 bit integer
it will be negative because the top bit is set. If you treat it as an unsigned 32 bit integer
its value is 4227858432 decimal. These are ‘equivalent’. Printf will try and print it exactly how you tell
it to, and in this case you used a “%d” format specifier so printf tries to print a signed integer.
You can print it in hex using printf(“0x%08X\n”, ALT_STM_OFFSET).

You absolutely must have an understanding of these basic C concepts or you’re really going
to find things very difficult indeed.

The way to determine if mmap passed or failed is to use exactly the code that’s already there,
which is, if( virtual_base == MAP_FAILED )
You’re using %s to sprintf a void *. Again, if you don’t understand a what a void * is I think you
need to improve your C skills.

As a plan of attack I suggest watch the above video about blinking LEDs, and also find a series of C tutorials on YouTube.

Good luck!


With the DE0-NANO-SOC CD (DE0-Nano-SoC_v.1.1.0_SystemCD.zip) comes a step by step doc to do that in

Source: Demonstrations\SoC_FPGA\HPS_CONTROL_FPGA_LED PDF: Manual\DE0-Nano-SoC_My_First_HPS-Fpga.pdf

Just did it, It works with QP 16.1 (my conf has patch:

Thanks very much, it helps to know that someone went through that tutorial successfully recently.