Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ARM programming mini2440 Friendly ARM NEWBIE SIMPLE CODES

Status
Not open for further replies.

firoz3321

Newbie level 5
Joined
Oct 3, 2008
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,350
Hi

I am using the Friendly ARM mini2440 kit.
I want to learn the C programming for this kit.

Please help me .

I need simple programs like LED , UART and ADC.

I tested the codes in the Examples that were givin with the kit. But those codes are writen i Device driver form (it opens some files kit) ( so i was told )

I want to write the basic codes from scratch. If i can fnd similar codes i would love to test them and understand them.

Please suggest me books that are related to the C programming for the mini2440.

I work in a small company and i am supposed to learn this kit. and from the past one month i have gone nowhere.


Please help me...
 

Hi

I am using the Friendly ARM mini2440 kit.
I want to learn the C programming for this kit.

First of all, you need to tell us which OS would you like to use. (Linux + QT, Ubuntu, CE) or would you like to crate your own distribution?
Eventually when you chosen the OS, you need to configure your developing environment.
Search for "dev. env for friendlyarm" for Linux env. you have all necessary tools on the DVD (gcc,...etc)


I need simple programs like LED , UART and ADC.
I tested the codes in the Examples that were givin with the kit. But those codes are writen i Device driver form (it opens some files kit) ( so i was told )
I want to write the basic codes from scratch. If i can fnd similar codes i would love to test them and understand them.
Please suggest me books that are related to the C programming for the mini2440.
I work in a small company and i am supposed to learn this kit. and from the past one month i have gone nowhere.
Please help me...

As I remember those LED , UART and ADC programs are fully working source code, you need only to compile it and run it in your environment.
Also you can find tips on FriendlyArm forum.

For the book you are asking... From your post i suggest you to start with any "how to learn C" one that i love is "Teach yourself C++ in one hour a day"
But I suggest you also to read stuff about embedded system.

Good luck. Bart
 

i am using REDHAT 5

Yes all the Example codes are working perfectly alright.
The entire environment is set up and is working fine.

But they are writen in DEVICE DRIVER format. I mean to say, those files open the files from the kit :

"fd = open("/dev/leds", 0);"

The sample codeis:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>

Code:
int main(int argc, char **argv)
{
	int on;
	int led_no;
	int fd;
	if (argc != 3 || sscanf(argv[1], "%d", &led_no) != 1 || sscanf(argv[2],"%d", &on) != 1 ||
	    on < 0 || on > 1 || led_no < 0 || led_no > 3) {
		fprintf(stderr, "Usage: leds led_no 0|1\n");
		exit(1);
	}
	fd = open("/dev/leds0", 0);
	if (fd < 0) {
		fd = open("/dev/leds", 0);
	}
	if (fd < 0) {
		perror("open device leds");
		exit(1);
	}
	ioctl(fd, on, led_no);
	close(fd);
	return 0;
}

This Code we modified from other sources and made it to work.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/mman.h>
#include "/usr/local/include/s3c2410-regs.h"
#include "uart.h"

#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \
  __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)

int running = 1;

void done (int sig)
{
    running = 0;
}


#define REQCNT 100              //May 08, 2002 SOP
#define ADC_FREQ 2500000
#define LOOP 10000
unsigned long led;
 int fd,fd1,fd2,fd3,led_no;

int main(int argc, char *argv[])
{

    signal (SIGINT, done);  // set up signal handler
    fd = open ("/dev/mem", O_RDWR | O_SYNC);

   GPIOp = mmap (0, sizeof (S3C2410_GPIO), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x56000000);

    printf ("\nThe Embedded Linux \n");

    GPIOp->GPBDAT=0x0000;

    while(1)
    {
    	printf ("\nSelect the LED(s) to glow :");
    	scanf("%d",&led_no);
    	printf ("\n");

    	switch(led_no)
    	{
    	case 1 :     GPIOp->GPBDAT=0x0020;
    			printf ("LED 1 \n");
    			break;

    	case 2 :     GPIOp->GPBDAT=0x0040;
			printf ("LED 2\n");
			break;

    	case 3 :     GPIOp->GPBDAT=0x0080;
			printf ("LED 3\n");
    			break;

    	case 4 :     GPIOp->GPBDAT=0x0100;
			printf ("LED 4\n");
    			break;

    	case 5 :     GPIOp->GPBDAT=~0x01E0;
			printf ("ALL LED ON\n");
    			break;

    	default  :    GPIOp->GPBDAT=~0x0000;
    			printf ("ALL LED OFF\n");
			break;
    	}

    }

    close (fd);

    if (munmap (GPIOp, sizeof (S3C2410_GPIO)) == -1){ }// FATAL;
    return 0;
}


I cant understand these commands:
GPIOp = mmap (0, sizeof (S3C2410_GPIO), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x56000000);

Isnt there any simpler method to switch ON the LEDs. Like I just need to pass the data to the PORTB.
 

I cant understand these commands:
Isnt there any simpler method to switch ON the LEDs. Like I just need to pass the data to the PORTB.

The way is done is because LEDs are memory maped (you can drive them if you put selected value on the address (in your case 00x56000000 for LEDs). This is how thinks are done in embedded systems. All devices are mmap-ed (memory maped). not sure what mmap do but
- sizeof(S3C2410_GPIO) get the value of S3C2410_GPIO variable (look at mman.h file)
- PROT_READ, PROT_WRITE, MAP_SHARED are flags
- fd ... feed
and the LEDs address
 

ADS v1.2 is very good for ARM9 based project especially for the mini2440 boards
You can start with simple LED glow program, hope this link will helpful
**broken link removed**
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top