Forum Discussion
Altera_Forum
Honored Contributor
15 years agoNIOS + MMU uClinux + PIO
Hi
I'd like to add same PIO to my nios and control it from linux. In menuconfig I added PIO led and buttons but I get errors while compilling. What should I add in nios.h? And then how controll it from uClinux with MMU. Is there any article about it?6 Replies
- Altera_Forum
Honored Contributor
Hi,
I am searching for the same thing for a while. I probably found a solution. Perhaps this might come handy: http://alteraforums.org/forum/showthread.php?p=67792 I don't have the time to test it now, but I will tomorrow. Urmel - Altera_Forum
Honored Contributor
Update:
Now I can set things like LED. All you have to do is write a c program, i.e. "ledtest.c"
But the most important part is the makefile. I took it from the generic-cgi folder and modified it to my needs. You have to add 'O2' to the flags otherwise the header file can't be found./* ledtest.c*/# include <stdio.h># include <asm/io.h> // if you like you can also include the header file with your base addresses of the board # define LED0 0x06 //the hex address for my first LED int main(void) { // ... my html code outl(LED0, LED_BASE) /* the first parameter of 'outl' is the value you want to set. The second is the base_address of the hardware you want to control. Either insert it manually or take the address from your included header file*/ return 0; } - Altera_Forum
Honored Contributor
--- Quote Start --- Update: Now I can set things like LED. All you have to do is write a c program, i.e. "ledtest.c"
But the most important part is the makefile. I took it from the generic-cgi folder and modified it to my needs. You have to add 'O2' to the flags otherwise the header file can't be found. --- Quote End --- This will only work without MMU. And -O2 means optimize, it has nothing to do with what files are included./* ledtest.c*/ # include <stdio.h> # include <asm/io.h> // if you like you can also include the header file with your base addresses of the board # define LED0 0x06 //the hex address for my first LED int main(void) { // ... my html code outl(LED0, LED_BASE) /* the first parameter of 'outl' is the value you want to set. The second is the base_address of the hardware you want to control. Either insert it manually or take the address from your included header file*/ return 0; } - Altera_Forum
Honored Contributor
--- Quote Start --- This will only work without MMU. And -O2 means optimize, it has nothing to do with what files are included. --- Quote End --- I have only worked on a version without MMU so I didn't knew that this wouldn't work. But good to know for the future. Ah damn, you are right with the optimize flag 'O2'. I knew it was for optimization but I also thought it was for proper including the right header files. But one of the flags '-o' or '-O2' is sufficient. But the reason why I couldn't include the asm/io.h was a failure in my own Makefile. The Makefile from the cgi_generic works. - Altera_Forum
Honored Contributor
--- Quote Start --- This will only work without MMU. And -O2 means optimize, it has nothing to do with what files are included. --- Quote End --- How to controll LEDs or PIO buttons on Linux with MMU? - Altera_Forum
Honored Contributor
Now I learned how to use LEDS or Buttons with NIOS MMU. This is quite simple with writing modules for kernel. This is simple one:
# include <linux/init.h> # include <linux/module.h> # include <linux/kernel.h> # include <asm/io.h> MODULE_LICENSE("GPL"); static void* ledg_vadd; static void* ledr_vadd; static int __init hello_init(void) { printk(KERN_ALERT "Hello, world\n"); ledg_vadd = ioremap(LEDS_G, 16); ledr_vadd = ioremap(LEDS_R, 16); if(ledg_vadd == NULL) { printk(KERN_ALERT "Adress is NULL"); return 0; } else { printk(KERN_INFO "Address LEDS_G is 0x%p\n", ledg_vadd); } if(ledr_vadd == NULL) { printk(KERN_ALERT "Adress is NULL"); return 0; } else { printk(KERN_INFO "Address LEDS_R is 0x%p\n", ledr_vadd); } writeb(13, ledg_vadd); writeb(15, ledr_vadd); return 0; } static void __exit hello_exit(void) { printk(KERN_ALERT "Goodbye, cruel world\n"); writeb(3, ledg_vadd); writeb(2, ledr_vadd); iounmap(ledg_vadd); iounmap(ledr_vadd); } module_init(hello_init); module_exit(hello_exit);