1. 서론
크로스 컴파일 환경 세팅하는건 나중에 시간되면 따로 글 올릴 예정
목표 : UDOO 보드에 있는 LED 제어
HOST (uame -a)
리눅스 버전 : Linux jaewon-VirtualBox 6.11.0-25-generic #25~24.04.1- Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 15 17:20:50 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
TARGET (uame -a)
Linux udoo 3.14.56-02048-geaaf16e- dirty #1 SMP PREEMPT Mon May 15 20:35:41 KST 2017 armv7l armv7l armv7l GNU/Linux
HOST와 Target의 리눅스 커널 버전이 다르므로 개발은 HOST에서 하되, 컴파일을 target 버전에 맞게끔 해주어야한다.
즉 크로스컴파일을 해주어야한다.
UDOO 보드에 맞는 커널 소스를 설치해주어야하는데 (== 크로스 컴파일 개발환경 세팅) 이건 나중에 시간 나면 따로 글을 올릴 예정이다.
2. led.ko (디바이스 드라이버) 작성 및 파일 전송
추가 예정
scp leddrv.ko ecube@192.168.137.192:/home/ecube/driver_sample/LED
3.ledTest.c 작성
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <sys/ipc.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define LED_DRIVER_NAME "/dev/periled"
void doHelp(void)
{
printf("Usage:\n");
printf("ledtest <hex byte> : data bit0 operation 1=>on 0=>off\n");
printf("ex) ledtest 0x04 : 3th led on\n");
printf(" ledtest 0x05 : 4th and 1th led on\n");
printf(" ledtest 0xff : all led on\n");
printf(" ledtest 0x00 : all led off\n");
}
int main(int argc , char **argv)
{
unsigned int data = 0;
int fd;
if (argc < 2 )
{
perror(" Args number is less than 2\n");
doHelp();
return 1;
}
data = strtol(argv[1],NULL,16);
printf("wrate data :0x%X\n", data);
// open driver
fd = open(LED_DRIVER_NAME,O_RDWR);
if ( fd < 0 )
{
perror("driver (//dev//cnled) open error.\n");
return 1;
}
write(fd,&data,4);
close(fd);
return 0;
}
4.크로스 컴파일 및 UDOO 보드로 파일 전송(SCP)
arm-linux-gnueabi-gcc -o ledTest.elf ledTest.c
scp ledTest.elf ecube@192.168.137.192:/home/ecube/driver_sample/LED
scp 경로 및 아이피 설정은 알잘딱
4.커널 모듈(leddrv.ko) 적재하기
2에서 전송한 leddrv.ko 파일을 udoo 보드에서 insmod 해준다.
/home/ecube/driver_sample/LED 경로로 파일을 전송했으니 해당 디렉토리 터미널에서 적재해줬다.
sudo insmod leddrv.ko
lsmod 확인
/dev/perild 확인
5.실행
sudo ./ledTest.elf 0xff // 모든 LED ON
'2025(학부 3학년) > 임베디드시스템' 카테고리의 다른 글
IPC(Inter Process Communication) (1) | 2025.06.08 |
---|---|
[UDOO] scp 파일 전송 (0) | 2025.05.13 |
[UDOO] SSH 연결 (0) | 2025.05.13 |
[UDOO] Serial 파일 전송 (0) | 2025.05.13 |
[UDOO] 네트워크 연결 (0) | 2025.05.13 |