這篇具有很好參考價(jià)值的文章主要介紹了嵌入式linux學(xué)習(xí)之實(shí)踐操作。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。
# 前沿
##1. 安裝交叉編譯器
* 在
開發(fā)板光盤
A-
基礎(chǔ)資料
->5
、開發(fā)工具
->1
、交叉編譯器
路徑下找到
st-example-image-qt
wayland-openstlinux-weston-stm32mp1-x86_64-toolchain-3.1-snapshot.sh
。將它拷貝到
Ubuntu 虛擬機(jī)上。 拷貝到 Ubuntu
后,賦予
st-example-image-qtwayland-openstlinux-weston-stm32mp1-x86_64-toolchain-3.1-snapshot.sh 可執(zhí)行權(quán)限。
*chmod +x st-example-image-qtwayland-openstlinux-weston-stm32mp1-x86_64-toolchain-3.1-snapshot.sh
* 執(zhí)行./st*.sh腳本安裝
* 安裝完成后,安裝的交叉編譯工具鏈都會(huì)安裝在
/opt/
目錄下。
* ls /opt/st/?
* 安裝完成之后,在使用之前先對(duì)交叉編譯工具的環(huán)境進(jìn)行設(shè)置,使用
source
執(zhí)行安裝目錄下的
environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
腳本文件即可,如下所示:
source /opt/st/stm32mp1/3.1-snapshot/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
注意:每個(gè)終端需要執(zhí)行上面的source命令之后,才能打印出${CC}.
使用${CC} -o led led.c編譯
生成的led可執(zhí)行文件通過scp命令傳輸?shù)介_發(fā)板,./led執(zhí)行。
# 1.控制led
```c
15_led.c:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define LED_TRIGGER "/sys/class/leds/user-led/trigger"
#define LED_BRIGHTNESS "/sys/class/leds/user-led/brightness"
#define USAGE() fprintf(stderr, "usage:\n" \
" %s <on|off>\n" \
" %s <trigger> <type>\n", argv[0], argv[0])
int
main
(
int
argc
,
char
*
argv
[])
{
int
fd1
,
fd2
;
/*
校驗(yàn)傳參
*/
if
(
2
>
argc
) {
USAGE
();
exit
(-
1
);
/*
打開文件
*/
fd1
=
open
(
LED_TRIGGER
,
O_RDWR
);
if
(
0
>
fd1
) {
perror
(
"open error"
);
exit
(-
1
);
}
fd2
=
open
(
LED_BRIGHTNESS
,
O_RDWR
);
if
(
0
>
fd2
) {
perror
(
"open error"
);
exit
(-
1
);
}
/*
根據(jù)傳參控制
LED */
if
(!
strcmp
(
argv
[
1
],
"on"
)) {
write
(
fd1
,
"none"
,
4
);
//
先將觸發(fā)模式設(shè)置為
none
write
(
fd2
,
"1"
,
1
);
//
點(diǎn)亮
LED
}
else if
(!
strcmp
(
argv
[
1
],
"off"
)) {
write
(
fd1
,
"none"
,
4
);
//
先將觸發(fā)模式設(shè)置為
none
write
(
fd2
,
"0"
,
1
);
//LED
滅
}
else if
(!
strcmp
(
argv
[
1
],
"trigger"
)) {
if
(
3
!=
argc
) {
USAGE
();
exit
(-
1
);
}
if
(
0
>
write
(
fd1
,
argv
[
2
],
strlen
(
argv
[
2
])))
perror
(
"write error"
);
}
else
USAGE
();
exit
(
0
);
}
```
使用${CC} -o 15_led 15_led.c編譯
在虛擬機(jī)使用ifconfig ens33 192.168.137.4配置ip
開發(fā)板ifconfig eth?192.168.137.3配置ip
開發(fā)板:scp tao@192.168.137.4:~/linux/c_cpp/15_led ~/將文件傳輸至開發(fā)板。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-824328.html
./15_led on點(diǎn)亮ds1,./15_led off熄滅ds1,./15_led trigger heartbeat使其閃爍。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-824328.html
也可以使用
DS0
進(jìn)行測(cè)試,將 源碼中的路徑修改一下即可(/sys/class/leds/user-led/
修改為
/sys/class/leds/sys-led/
)
# 操作GPIO
到了這里,關(guān)于嵌入式linux學(xué)習(xí)之實(shí)踐操作的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!
本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!