Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers

uCLinux

Altera_Forum
Honored Contributor II
1,616 Views

Hi everyone 

I really need some help! I try to install uClinux on my development board from Altera (it is a DE1 development board). I do not want to use the design files but my own system. So I built my system, obtained a .ptf file, download the kernel image of uClinux and my .sof file. Everything works: my FPGA is configured and my zImage is downloaded oin my sram. But now I want to run a simple code with interruptions of GPIO and stuff like that. But how do I do that? how can I compile my programm and run it? 

thank you
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
840 Views

wrong section, there is uClinux Section here http://www.niosforum.com/pages/forum.php?cat_id=5

0 Kudos
Altera_Forum
Honored Contributor II
840 Views

There are several ways to run a custom program on a uClinux System, anyway, i have used two: 

 

1. Include in your kernel configuration the SD Card Driver and the FAT filesystems (http://www.nioswiki.com/operatingsystems/uclinux/mmcsd). Compile and link your program and copy the generated binary to SD from a PC with SD Card reader. Mount your SD as indicated in link, enter to its location and run (./your_program). 

 

2. You can mount a NFS (network filesystem) client (http://www.nioswiki.com/operatingsystems/uclinux/nfsfilesytem) on your uClinux, so, you can copy from/to a NFS server (preferably a Linux machine). Compiling is done as in 1.
0 Kudos
Altera_Forum
Honored Contributor II
840 Views

Thanks parrado for your answer. 

It seems to be very complicated to me. But I will try your solution as soon as possible. I have also tried to do as indicated in this website http://www.nioswiki.com/operatingsystems/uclinux/compilehello 

I copied my program (a simple hello world to begin) in the romfs and after that I build my zImage which I downloaded and run on nios2-terminal. Can I do thongs like that or is it not a good way to join a .c file to my kernel?? 

Thank you again for your answer 

éléa
0 Kudos
Altera_Forum
Honored Contributor II
840 Views

Yeah, that's other option i've used also. 

 

The problem with this approach is the kernel re-building needed, this takes more time than building your application with a own makefile and storing the binary file in SD or USB pen drive.
0 Kudos
Altera_Forum
Honored Contributor II
840 Views

Again thank you parrrado 

I have another question. I made a program to handle the interrupts when I worked without µClinux in Nios IDE. Do I have to made modifications so that µClinux can read this program and do what I want my nios to do? Here is my program:# include "alt_types.h"# include "altera_avalon_pio_regs.h"# include "sys/alt_irq.h"# include "system.h"# include <stdio.h># include <unistd.h> 

 

volatile int edge_capture; 

# ifdef GPIO_A0_BASE# ifdef SORTIE_GPIO_1_BASE 

static void handle_button_interrupts(void* context, alt_u32 id) 

/* Cast context to edge_capture's type. It is important that this be  

* declared volatile to avoid unwanted compiler optimization. 

*/ 

volatile int *edge_capture_ptr = (volatile int*) context; 

/* Store the value in the PIO's edge capture register in *context. */ 

*edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(GPIO_A0_BASE); 

IOWR_ALTERA_AVALON_PIO_DATA(SORTIE_GPIO_1_BASE,1); 

 

/* Reset the PIO's edge capture register. */ 

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(GPIO_A0_BASE, 0); 

IORD_ALTERA_AVALON_PIO_EDGE_CAP(GPIO_A0_BASE); //An extra read call to clear of delay through the bridge 

IOWR_ALTERA_AVALON_PIO_DATA(SORTIE_GPIO_1_BASE,0); 

/* Initialize the GPIO_INPUT. */ 

static void init_GPIO_A0() 

/* Recast the edge_capture pointer to match the alt_irq_register() function 

* prototype. */ 

void* edge_capture_ptr = (void*) &edge_capture; 

/* Enable the PIO interrupt. */ 

IOWR_ALTERA_AVALON_PIO_IRQ_MASK(GPIO_A0_BASE, 0xf); 

/* Reset the edge capture register. */ 

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(GPIO_A0_BASE, 0x0); 

/* Register the interrupt handler. */ 

alt_irq_register( GPIO_A0_IRQ, edge_capture_ptr, 

handle_button_interrupts ); 

}# endif# endif 

 

 

int main(void) 

# ifdef GPIO_A0_BASE 

init_GPIO_A0();  

# endif 

 

while(1) 

if (edge_capture!=0) 

# ifdef LED_R_BASE 

IOWR_ALTERA_AVALON_PIO_DATA(LED_R_BASE,1); 

usleep(10); 

IOWR_ALTERA_AVALON_PIO_DATA(LED_R_BASE,0); 

# endif 

edge_capture=0;  

}  

return 0; 

}
0 Kudos
Altera_Forum
Honored Contributor II
840 Views

This is taken from http://www.nioswiki.com/operatingsystems/uclinux/compilehello 

 

 

--- Quote Start ---  

 

IO programming in user space. 

Edit section 

 

Note, you are doing in user space, with uclibc and included from /opt/nios2/include. It is not kernel space. You can not use interrupt. You can not use nios2 HAL, either. 

 

You should know about the cache in Nios II. (BadOman:?) The first 2GB of address space is cached. The second 2GB is non-cached. These are not two seperate memory spaces or anything so there is a total of 2GB of address space (mirrored memory). This only applies for Nios II Full version with Data Cache. Nios II Standard version is uncached, so there should be no problems. 

 

In other words address 0x00000000 (cachable) maps to address 0x8000000 (non-cachable) 

" " " " " " 0x00000001 " " " " " " " " 0x8000001 (and so on .....) 

 

So use the first 2GB for non-peripheral access (local memory), and the second 2GB for peripherals 

 

You can define memory pointer access, and you can make it uncached by setting address bit 31. 

eg, 0x00004000 -> 0x80004000 

 

Or use port address defined in nios2_system.h, eg na_button_pio. 

# include </home/hippo/uClinux-dist/linux-2.6.x/include/nios2_system.h> 

 

# define inw(port) (*(volatile unsigned *)(port)) # for io read, 

# define outw(d,port) (*(volatile unsigned *)(port))=(d) # for io write, 

 

As an alternative, you can use these two defines (which are always uncached), they are similar to the Nios2-IDE functions : 

# define IORD(address,offset) (*(volatile unsigned *)(((address)|0x80000000)+4*(offset))) 

# define IOWR(address,offset,value) (*(volatile unsigned *)(((address)|0x80000000)+4*(offset)))=(value) 

 

--- Quote End ---  

 

 

So you can access with two last macros, like with nios2eds, your hardware in user space. 

 

In case of interrupt you must handle it in kernel space, so you must write a driver (http://www.nioswiki.com/operatingsystems/uclinux/moduleprogramming

 

as i see, your input device is a button-pio, check this file in you uclinux distro.  

\linux-2.6\drivers\char 

 

it could help.
0 Kudos
Altera_Forum
Honored Contributor II
840 Views

Hi sir  

i am stephen , i am trying to install uClinux to NIOS 2 board but i cannot do it because i have not correct procedure . 

sir plese give me the step by step procedure to install uClinux to NIOS 2 board 

 

note : 

Os name:  

kernal version: 

uClinux version: 

 

please give men the above details sir 

 

 

by 

stephen
0 Kudos
Reply