|
1. Install cross-build compiler
AM¿ë ÀÓº£µðµå ¸®´ª½ºÀÇ ¾îÇø®ÄÉÀ̼ÇÀ» °³¹ßÇϱâ À§Çؼ´Â ÄÄÆÄÀÏ·¯·Î °³¹ß¿ë Linux PC¿¡ ARM¿ë Å©·Î½º ÄÄÆÄÀÏ·¯¸¦ ¼³Ä¡
ÇØ¾ß ÇÕ´Ï´Ù. ÀÌ °³¹ßº¸µå¸¦ À§Çؼ´Â arm-linux-gcc-4.5.1 ÄÄÆÄÀÏ·¯¸¦ ¼³Ä¡ ÇØ¾ß ÇÕ´Ï´Ù. ÀÌ ÄÄÆÄÀÏ·¯´Â armv6
Instruction set and support hardware floating-point operations µîÀ» Áö¿ø
ÇÕ´Ï´Ù. ÀÚ¼¼ÇÑ ¼³Ä¡ ¹æ¹ýÀº ¸®´ª½º °³¹ßÀÚ °¡À̵带 ÂüÁ¶ÇϽñ⠹ٶø´Ï´Ù.
1.
Linux °³¹ßÀÚ °¡À̵å(Ä¿³Î ÄÄÆÄÀÏ, ÆÄÀϽýºÅÛ, Qt Æ÷Æà µî)
°³¹ßº¸µå¿¡ ´ëÇÑ ¸ðµç ÄÜ¼Ö ¾îÇø®ÄÉÀÌ¼Ç ¼Ò½º´Â CD/Linux/examples-mini210-20111119.tga ÆÄÀÏ·Î ¾ÐÃàÀÌ µÇ¾î ÀÖ½À´Ï´Ù.
1.1 Hello, World!
Hello, World ¿¹Á¦ÀÇ ¼Ò½ºÄÚµå´Â "/opt/FriendlyARM/tiny210/linux/examples/hello"
¿¡ ÀÖ½À´Ï´Ù.
#include
<stdio.h>
int main(void) {
printf("hello, FriendlyARM!\n");
} |
Step1 : Compile Hello, World
# cd
/opt/FriendlyARM/tiny210/linux/examples/hello
# make
ÄÄÆÄÀÏÀÌ ¿Ï·áµÈ ¹ÙÀ̳ʸ® ÆÄÀÏÀÇ Á¤º¸¸¦ º¼ ¼ö ÀÖ½À´Ï´Ù.
Step2 : Download Hello, World example to development board
°³¹ßº¸µå¿¡ ÄÄÆÄÀÏµÈ ¿¹Á¦¸¦ ´Ù¿î·Îµå ÇÏ´Â ¹æ¹ý¿¡´Â 4°¡Áö Á¤µµÀÇ ¹æ¹ýÀÌ ÀÖ½À´Ï´Ù.
(1) FTP¸¦ ÀÌ¿ëÇÑ ´Ù¿î·ÎµåÇÏ´Â ¹æ¹ý
(2) USB ¸Þ¸ð¸® or SD ¸Þ¸ð¸® Ä«µå¸¦ ÀÌ¿ëÇؼ Ÿ°Ù º¸µå¿¡ ¸¶¿îÆ® ÈÄ º¹»çÇÏ´Â ¹æ¹ý
(3) ½Ã¸®¾ó Æ÷Æ®¸¦ ÀÌ¿ëÇؼ ´Ù¿î·Îµå ÇÏ´Â ¹æ¹ý
(4) NFS¸¦ ÀÌ¿ëÇؼ ¹Ù·Î ½ÇÇà ÇÏ´Â ¹æ¹ý
(1) FTP¸¦ ÀÌ¿ëÇÑ ´Ù¿î·ÎµåÇÏ´Â ¹æ¹ý (recommended)
¾Æ·¡¿Í °°ÀÌ °³¹ß¿ë Linux PC¿¡¼ Ÿ°Ù º¸µå¿¡ FTP·Î Á¢¼ÓÈÄ ´Ù¿î·Îµå ÇÕ´Ï´Ù.
´Ù¿î·Îµå°¡ ¿Ï·áµÇ¸é Ÿ°Ù º¸µå¿¡¼ ´Ù¿î·ÎµåÇÑ ÆÄÀÏ¿¡ ½ÇÇà ±ÇÇÑÀ» ºÎ¿© ÇÕ´Ï´Ù.
(2) USB ¸Þ¸ð¸® or SD ¸Þ¸ð¸® Ä«µå¸¦ ÀÌ¿ëÇؼ Ÿ°Ù º¸µå¿¡ ¸¶¿îÆ® ÈÄ º¹»çÇÏ´Â ¹æ¹ý
PC¿¡¼ ¾Æ·¡ ¸í·ÉÀ» ÀÌ¿ëÇؼ USB ¸Þ¸ð¸®¸¦ ¸¶¿îÆ® ÇÑ´ÙÀ½ ¿¹Á¦ ÆÄÀÏÀ» USB¸Þ¸ð¸®¿¡ º¹»çÇÕ´Ï´Ù.
# mount /dev/sda1 /mnt
# cp hello /mnt
# umount /mnt
USB ¸Þ¸ð¸®¸¦ Ÿ°Ù °³¹ßº¸µå¿¡ ¿¬°á Çϸé ÀÚµ¿À¸¸® /udisk·Î ¸¶¿îÆ®°¡ µÇ°í ¾Æ·¡°ú °°Àº ¸í·ÉÀ¸·Î ½ÇÇà ÇØ º¼ ¼ö ÀÖ½À´Ï´Ù.
# cd /udisk
# ./hello
(3) ½Ã¸®¾ó Æ÷Æ®¸¦ ÀÌ¿ëÇؼ ´Ù¿î·Îµå ÇÏ´Â ¹æ¹ý
½Ã¸®¾óÀ» ÅëÇÑ ÆÄÀÏ ´Ù¿î·Îµå ÇÏ´Â ¹æ¹ýÀº ¸®´ª½º »ç¿ëÀÚ °¡À̵å "1.2.4 ½Ã¸®¾ó Æ÷Æ®¸¦ ÀÌ¿ëÇÑ PCÆÄÀÏ Àü¼Û" À» ÂüÁ¶ÇϽñâ
¹Ù¶ø´Ï´Ù.
´Ù¿î·ÎµåÇÑ ÆÄÀÏ¿¡ ½ÇÇà ±ÇÇÑÀ» ºÎ¿© ÇÕ´Ï´Ù.
# chmod +x hello
(4) NFS¸¦ ÀÌ¿ëÇؼ ¹Ù·Î ½ÇÇà ÇÏ´Â ¹æ¹ý
"192.168.1.111" ´Â NFS¼¹ö PCÀÇ IP ÁÖ¼Ò ÀÔ´Ï´Ù.
# mount -t nfs -o nolock
192.168.1.111:/opt/FriendlyARM/tiny210/linux/rootfs_qtopia_qt4 /mnt
NFS¸¶¿îÆ®°¡ ¼º°øÀûÀ¸·Î ¿¬°áÀÌ µÇ¸é /mnt µð·ºÅ丮¿¡ NFS¼¹öÀÇ
"opt/FriendlyARM/tiny210/linux/rootfs_qtopia_qt4" µð·ºÅ丮°¡ ¸¶¿îÆ® µÇ¾î Á¢±Ù ÇÒ ¼ö
ÀÖ½À´Ï´Ù.
# cd /mnt
# ./hello
1.2 LED Test Program
µð¹ÙÀ̽º µå¶óÀ̹ö À§Ä¡ | /opt/FriendlyARM/tiny210/linux/linux-2.6.35.7/drivers/char |
µå¶óÀ̹ö ¼Ò½º ÆÄÀÏ À̸§ |
mini210_leds.c |
Device Type |
misc |
Device Name |
/dev/leds |
¼Ò½º µð·ºÅ丮 |
/opt/FriendlyARM/tiny210/linux/examples/leds |
¿¹Á¦ À̸§ |
led.c |
¿¹Á¦ ½ÇÇà ÆÄÀÏ À̸§ |
led |
LED driver has been compiled
into the default kernel, so can not be loaded using insmod. |
#include
<stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
int main(int argc, char **argv)
{
int on;
int led_no;
int fd;
/* check led control of two parameters, if no parameter input is out. */
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);
}
/* open /dev/ leds device file */
fd = open("/dev/leds0", 0);
if (fd < 0) {
fd = open("/dev/leds", 0);
}
if (fd < 0) {
perror("open device leds");
exit(1);
}
/* the ioctl system call and input the parameter control led */
ioctl(fd, on, led_no);
/* close the device handle */
close(fd);
return 0;
} |
ÄÄÆÄÀÏÇÏ°í Ÿ°Ùº¸µå¿¡ ´Ù¿î·Îµå Çؼ ½ÇÇàÇÏ´Â ¹æ¹ýÀº Hello, World ¿¹Á¦¿Í µ¿ÀÏ ÇÕ´Ï´Ù.
1.3 Button Test Program
µå¶óÀ̹ö ¼Ò½º µð·ºÅ丮 |
/opt/FriendlyARM/tiny210/linux/linux-2.6.35.7/drivers/char |
µå¶óÀ̹ö ¼Ò½º ÆÄÀÏ À̸§ |
mini210_buttons.c |
Device Type |
misc |
Device Name |
/dev/buttons |
¼Ò½º µð·ºÅ丮 |
/opt/FriendlyARM/tiny210/linux/examples/buttons |
¿¹Á¦ À̸§ |
buttons_test.c |
¿¹Á¦ ½ÇÇà ÆÄÀÏ À̸§ |
buttons |
Button driver has been
compiled into the default kernel, so can not be loaded using insmod. |
#include
<stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>
int main(void)
{
int buttons_fd;
char buttons[6] = {'0', '0', '0', '0', '0', '0'};
buttons_fd = open("/dev/buttons", 0);
if (buttons_fd < 0) {
perror("open device buttons");
exit(1);
}
for (;;) {
char current_buttons[6];
int count_of_changed_key;
int i;
if (read(buttons_fd, current_buttons, sizeof current_buttons) != sizeof
current_buttons) {
perror("read buttons:");
exit(1);
}
for (i = 0, count_of_changed_key = 0; i < sizeof buttons /
sizeof buttons[0]; i++) {
if (buttons[i] != current_buttons[i]) {
buttons[i] = current_buttons[i];
printf("%skey %d is %s", count_of_changed_key? ", ": "", i+1,
buttons[i] ==
'0' ? "up" : "down");
count_of_changed_key++;
}
}
if (count_of_changed_key) {
printf("\n");
}
}
close(buttons_fd);
return 0;
}
|
1.4 PWM Buzzer Test Program
µå¶óÀ̹ö ¼Ò½º µð·ºÅ丮 |
/opt/FriendlyARM/tiny210/linux/linux-2.6.35.7/drivers/char |
µå¶óÀ̹ö ¼Ò½º ÆÄÀÏ À̸§ |
mini210_pwm.c |
Device Type |
misc |
Device Name |
/dev/pwm |
¼Ò½º µð·ºÅ丮 |
/opt/FriendlyARM/tiny210/linux/examples/pwm |
¿¹Á¦ À̸§ |
pwm_test.c |
¿¹Á¦ ½ÇÇà ÆÄÀÏ À̸§ |
Pwm_test |
PWM driver has been compiled
into the default kernel, so can not be loaded using insmod. |
#include
<stdio.h>
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
#define PWM_IOCTL_SET_FREQ 1
#define PWM_IOCTL_STOP 2
#define ESC_KEY 0x1b
static int getch(void)
{
struct termios oldt,newt;
int ch;
if (!isatty(STDIN_FILENO)) {
fprintf(stderr, "this problem should be run at a terminal\n");
exit(1);
}
// save terminal setting
if(tcgetattr(STDIN_FILENO, &oldt) < 0) {
perror("save the terminal setting");
exit(1);
}
// set terminal as need
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
if(tcsetattr(STDIN_FILENO,TCSANOW, &newt) < 0) {
perror("set terminal");
exit(1);
}
ch = getchar();
// restore termial setting
if(tcsetattr(STDIN_FILENO,TCSANOW,&oldt) < 0) {
perror("restore the termial setting");
exit(1);
}
return ch;
}
static int fd = -1;
static void close_buzzer(void);
static void open_buzzer(void)
{
fd = open("/dev/pwm", 0);
if (fd < 0) {
perror("open pwm_buzzer device");
exit(1);
}
// any function exit call will stop the buzzer
atexit(close_buzzer);
}
static void close_buzzer(void)
{
if (fd >= 0) {
ioctl(fd, PWM_IOCTL_STOP);
close(fd);
fd = -1;
}
}
static void set_buzzer_freq(int freq)
{
// this IOCTL command is the key to set frequency
int ret = ioctl(fd, PWM_IOCTL_SET_FREQ, freq);
if(ret < 0) {
perror("set the frequency of the buzzer");
exit(1);
}
}
static void stop_buzzer(void)
{
int ret = ioctl(fd, PWM_IOCTL_STOP);
if(ret < 0) {
perror("stop the buzzer");
exit(1);
}
}
int main(int argc, char **argv)
{
int freq = 1000 ;
open_buzzer();
printf( "\nBUZZER TEST ( PWM Control )\n" );
printf( "Press +/- to increase/reduce the frequency of the BUZZER\n" ) ;
printf( "Press 'ESC' key to Exit this program\n\n" );
while( 1 )
{
int key;
set_buzzer_freq(freq);
printf( "\tFreq = %d\n", freq );
key = getch();
switch(key) {
case '+':
if( freq < 20000 )
freq += 10;
break;
case '-':
if( freq > 11 )
freq -= 10 ;
break;
case ESC_KEY:
case EOF:
stop_buzzer();
exit(0);
default:
break;
}
}
}
|
1.5 I2C-EEPROM programming example
µå¶óÀ̹ö ¼Ò½º µð·ºÅ丮 |
/opt/FriendlyARM/tiny210/linux/linux-2.6.35.7/drivers/i2c/busses |
µå¶óÀ̹ö ¼Ò½º ÆÄÀÏ À̸§ |
I2c-s3c2410.c |
Device Type |
Char device |
Device Name |
/dev/i2c/0 |
¼Ò½º µð·ºÅ丮 |
/opt/FriendlyARM/tiny210/linux/examples/i2c |
¿¹Á¦ À̸§ |
eeprog.c 24cXX.c |
¿¹Á¦ ½ÇÇà ÆÄÀÏ À̸§ |
i2c |
PWM driver has been compiled
into the default kernel, so can not be loaded using insmod. |
#include
<stdio.h>
#include <fcntl.h>
#include <getopt.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "24cXX.h"
#define usage_if(a) do { do_usage_if( a , __LINE__); } while(0);
void do_usage_if(int b, int line)
{
const static char *eeprog_usage =
"I2C-24C08(256 bytes) Read/Write Program, ONLY FOR TEST!\n"
"FriendlyARM Computer Tech. 2009\n";
if(!b)
return;
fprintf(stderr, "%s\n[line %d]\n", eeprog_usage, line);
exit(1);
}
#define die_if(a, msg) do { do_die_if( a , msg, __LINE__); } while(0);
void do_die_if(int b, char* msg, int line)
{
if(!b)
return;
fprintf(stderr, "Error at line %d: %s\n", line, msg);
fprintf(stderr, " sysmsg: %s\n", strerror(errno));
exit(1);
}
static int read_from_eeprom(struct eeprom *e, int addr, int size)
{
int ch, i;
for(i = 0; i < size; ++i, ++addr)
{
die_if((ch = eeprom_read_byte(e, addr)) < 0, "read error");
if( (i % 16) == 0 )
printf("\n %.4x| ", addr);
else if( (i % 8) == 0 )
printf(" ");
printf("%.2x ", ch);
fflush(stdout);
}
fprintf(stderr, "\n\n");
return 0;
}
static int write_to_eeprom(struct eeprom *e, int addr)
{
int i;
for(i=0, addr=0; i<256; i++, addr++)
{
if( (i % 16) == 0 )
printf("\n %.4x| ", addr);
else if( (i % 8) == 0 )
printf(" ");
printf("%.2x ", i);
fflush(stdout);
die_if(eeprom_write_byte(e, addr, i), "write error");
}
fprintf(stderr, "\n\n");
return 0;
}
int main(int argc, char** argv)
{
struct eeprom e;
int op;
op = 0;
usage_if(argc != 2 || argv[1][0] != '-' || argv[1][2] != '\0');
op = argv[1][1];
fprintf(stderr, "Open /dev/i2c/0 with 8bit mode\n");
die_if(eeprom_open("/dev/i2c/0", 0x50, EEPROM_TYPE_8BIT_ADDR,
&e) < 0,
"unable to open eeprom device file "
"(check that the file exists and that it's readable)");
switch(op)
{
case 'r':
fprintf(stderr, " Reading 256 bytes from 0x0\n");
read_from_eeprom(&e, 0, 256);
break;
case 'w':
fprintf(stderr, " Writing 0x00-0xff into 24C08 \n");
write_to_eeprom(&e, 0);
break;
default:
usage_if(1);
exit(1);
}
eeprom_close(&e);
return 0;
}
|
|