上次已经开启了Linux系统,并且有GUI桌面,虽然不是比较熟悉的Qt环境,但也是可以做个小应用感受下stm32mp135系列产品的特点。 首先要搭建开发环境,毫无疑问安装个SDK就行了,官方WiKi页面啥都有。
) |% o$ x- w4 s: J4 P5 J2 V2 G 基于Ubuntu18系统,补充安装所需要的库和小工具
1 n8 h( D) g4 [6 `3 ` Y% k 更新软件列表 安装python3
# `2 b* |5 O9 r( p" `- sudo apt-get install gawk wget git diffstat unzip texinfo gcc-multilib chrpath socat cpio python3 python3-pip python3-pexpect
复制代码 其他工具- sudo apt-get install libssl-dev libgmp-dev libmpc-dev lz4 zstd
复制代码 编译器等组件 - sudo apt-get install build-essential libncurses-dev libyaml-dev libssl-dev
复制代码 默认使用python3 - sudo apt install python-is-python3
复制代码 其他有用的工具 - sudo apt-get install coreutils bsdmainutils sed curl bc lrzsz corkscrew cvs subversion mercurial nfs-common nfs-kernel-server libarchive-zip-perl dos2unix texi2html libxml2-utils
复制代码 执行完以上内容,就可以下载和安装SDK软件包了。从以下地址获取最新的SDK https://www.st.com/en/embedded-software/stm32mp1dev.html#get-software7 }! w( m- k' \: l3 x2 ]
我还是在windows下面下载的,然后拷贝到了虚拟机使用。使用tar xvf 解压该压缩包。chmod +x 赋予可执行权限。然后运行安装就行了,默认的目录是/opt/st/stm32mp1/,,这个路径就可以,直接继续安装。+ t6 M- X& c$ t* Q. ~
8 w1 A0 S8 m. ?/ {
然后就学着官方文档的样子去验证下SDK是否安装成功。
/ ?1 z K/ |4 e4 y1 g( |5 i& a* p
3 }- V, j" J& n
以上就完成了编译环境,至于说开发环境,一般还得有个IDE或者其他编辑器加调试工具。这里打算做的小程序使用gedit就行。
3 K" ^7 n3 y8 u% X* I) W 首先拷贝官方给的demo程序,基于GTK得hello world。+ h! w' W4 X _( m" o: [8 u
7 j0 _8 q7 w( M3 k3 s
- #include <gtk/gtk.h>6 a" ^ V/ D/ G2 ~- F
- ' \& N/ S1 Y4 L3 R4 _ t3 ^0 s, y
- static void
# S, j7 N+ a0 Q8 f3 F/ [ - print_hello (GtkWidget *widget,1 Z* p; l. I) I) @7 u
- gpointer data)3 _8 O4 ~! c6 M% J
- {, X' X& B7 Y1 r' C! ] W
- g_print ("Hello World\n");
% w5 A' y* O8 B x4 Z+ ~5 r" t, i - }
5 d' C( Q- M' B. K) c% N% C/ A
A" e4 l3 M) b) V- static void/ m8 O: E6 p( s! Y8 M9 ^9 g
- activate (GtkApplication *app,8 i, Z1 u0 @; r! o. E0 ~
- gpointer user_data)# @9 L! A. Z+ L. U R9 _9 x+ L
- {
$ N, e2 f0 t- @* I - GtkWidget *window;
E: ^1 n) M& v7 N - GtkWidget *button;
/ }5 ]) B7 r$ _* R7 t, \ - GtkWidget *button_box;: C/ D) a( U: ^2 l
( p0 [0 C n' B; a Z J- window = gtk_application_window_new (app);
, l a" G! u* {( Z: v - gtk_window_set_title (GTK_WINDOW (window), "Window");
1 O$ F2 k$ ^- a; c* r+ T$ Q - gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);% X% ^& {2 `6 ~
9 _, } k x! G, L- button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
, ~ O5 o9 a4 H - gtk_container_add (GTK_CONTAINER (window), button_box);
. x. R& W' Y0 J9 G# P( M
/ e) F7 a1 i" z. |8 b8 b+ `, k- button = gtk_button_new_with_label ("Hello World");. u6 t1 A! ]7 _( C% l
- g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
; }2 M# \) t% S% E - g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
) D5 K- ]: k0 G0 w, F; c" F - gtk_container_add (GTK_CONTAINER (button_box), button);9 ~' D" q, I9 V$ z
4 d/ ~' U: ~2 p) v# F: K" b7 O4 S3 W- gtk_widget_show_all (window);* V$ z v7 p. z: p
- }6 o4 \ f& g' K. V8 M) E
6 f: l* ]1 |, Q& T- int; h1 W2 l5 |8 J1 ~& o
- main (int argc,: S% j K8 v1 c0 Z+ P* b
- char **argv)
$ Y8 R+ a' r$ |' }7 D3 |! U - {
- N! ?: t/ Q( f& \5 I - GtkApplication *app;
1 I0 T. u* P' E- V5 z) e6 c - int status;( v% w& w2 | Y" _
- 0 Q/ t" _* A% t' z! R* |
- app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
% k3 p( N8 @* H* x. _' d { - g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); V- ^% f/ p& m, x: f/ D
- status = g_application_run (G_APPLICATION (app), argc, argv);
- D; v" a# D6 x; K* _ - g_object_unref (app);/ |& c+ y/ u% h+ p! Y7 P) O
+ a' V1 z/ x4 T4 }- return status;, m' J& Q, H: C! ~ v n
- }
复制代码 然后也复制一个makefile文件,其实单个文件,直接使用gcc命令也可以得。 - PROG = gtk_hello_world$ o4 n+ _' q2 }: y2 r+ p
- SRCS = gtk_hello_world.c
) y7 Q4 O7 o2 m. l! F
+ ]! O n* x5 i% T$ S! T& ~- CLEANFILES = $(PROG)
3 @( V* m6 {# d' F - 4 ?6 a: I# ^& W3 J. V. S
- # Add / change option in CFLAGS and LDFLAGS. m1 z6 l5 G; M
- CFLAGS += -Wall $(shell pkg-config --cflags gtk+-3.0). @" |5 c$ Y$ i* z* W1 e
- LDFLAGS += $(shell pkg-config --libs gtk+-3.0)
$ R9 c# F# q% `3 z2 o9 H1 n
* ]: `2 j n, a5 n: ~- all: $(PROG)0 o2 U) N* l C, k
# P: n% ^& C# I j/ M" v5 {( q- $(PROG): $(SRCS)
8 y8 M3 ]( m0 r! N3 t8 k9 d - $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
* T3 i8 F0 P8 C6 \# ~) y7 L - ; ?; ^0 m% Q) S+ `1 ~$ G8 K; U
- clean:3 g! G/ j3 k2 ?$ H
- rm -f $(CLEANFILES) $(patsubst %.c,%.o, $(SRCS))
复制代码 然后make,scp到开发板执行程序,就可以看到一个hello world窗口出现在之前得桌面上了。3 M/ G8 [; \" q5 h4 q! S
2 c* ?2 X2 a* U3 z. a3 k6 q' j: u% t 接下来改程序,说实话没用过gtk,不过看了下helloworld得程序可以看懂,所以也百度了一下,就基本做出来了。
0 }8 z4 g9 e2 i$ Z' X( I* b, O! K" |0 O: k) d0 {/ ~: F- ^& E
- #include <gtk/gtk.h>" G- y, J; Y7 `, W/ V9 G
- #include <stdio.h>/ P* W# Q4 H( a: m$ C2 ~
- #include <string.h>/ w2 w% w/ \' B( [3 o' h4 j* X5 [
-
" D o- g* R" g; o - char buf[50] = "";
+ A0 F* _7 p6 I0 b - 2 A4 t0 o; `: m* F/ T
- void calc(GtkButton *button, gpointer data)5 Y; ~, L* @* b$ X1 Q$ B
- {! @4 _& k# X# I
- const char *text = gtk_button_get_label(button);
7 Y; J! d0 }8 [7 k* c$ p4 z - + j3 H' U4 l7 X3 E+ E. R
- //退个操作8 Y- X/ ?; p. {( P3 t
- if (0 == strcmp(text, "c"))
# q' L- p; ?& y - {- j% t9 n% t! z4 d1 h
- buf[strlen(buf) - 1] = 0;
- N G. X& t5 T* L# _) O - }else{
* P: P- t/ v! }. u# A9 t3 j - * Y8 V \8 P0 C* P: }# M" d% J
- int a = 0, b = 0;( ?# Q6 c o/ b
- char c;
3 Z% w$ x H& M) c1 I% h1 e$ \ - strcat(buf,text);; A o; b: A. b; {* F# [
-
7 F5 j4 j W1 e$ j - if (0 == strcmp("=", text)) {
9 N, c4 p3 B7 `0 p -
: k: a5 @0 j) k/ O# y" [ - sscanf(buf, "%d%c%d", &a, &c, &b);
0 Q. p- r7 U! `4 ?/ ], F6 W -
! \* z: H$ u! y& E8 d - if ('+' == c) {
, s: k k6 S5 ~+ U3 [9 M - sprintf(buf,"%d", a+b);
% v% V5 Z7 Y. W- T) c# F - }+ p' t! ^2 U; _3 C2 e2 B& L
- else if ('-' == c) {
7 ?! v! U$ y* K - sprintf(buf, "%d", a-b);# t7 v3 F0 o& w/ M7 o- |* r
- }
* E/ X' v4 C" b0 u: s0 e - else if ('*' == c) {
! @( E# {- b2 y5 w- A5 _ - sprintf(buf, "%d", a*b);
' U$ I8 e s5 Y3 Z- p. i9 T' ~$ [ - }( I& M- ?* h1 d$ f0 V
- else if ('/' == c) {
: \5 C6 u$ s- k" C - sprintf(buf, "%d", a/b);
- Y& h6 J6 @% e! g U5 v - }. S/ C' T: w* C4 p% |
-
P6 @5 S2 W# p" ]' G3 ? - }
; Q- ?* ?3 q( E5 x; Y. y - }9 o( a# \# c4 C1 H1 s7 @+ l$ l
-
6 T" _8 U, Q. i% u4 T9 y" {& G - gtk_entry_set_text(GTK_ENTRY(data), buf);3 u4 V( o* y' N, X" U
- 9 L. O# m% G0 w
- return;
o2 o% O, c. F& J1 I/ z - }
& D/ E, [# S& D. O5 z% V -
+ H/ i& T% k$ Z2 A% l% K0 E" _* J: Q - int main(int argc,char *argv[])
# B& B% r q0 P/ w1 B1 ]: g - {* j. x) _ ]7 c8 q1 s' C4 b1 V3 V
- 0 L+ C% l$ h' p0 ?1 c9 c
- gtk_init(&argc, &argv);7 V( n# ?* C; p9 E9 o
-
' X V: d) C, c9 L" Z$ T1 _
# ` z0 g* p, y! [; v0 Q4 t$ @- GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
7 s! g. M- x- x( h) e/ B - gtk_window_set_title (GTK_WINDOW (window), "calc");8 g" F% b5 u- U9 I$ {# _' Q
-
0 }5 f$ v# o( Y! f - //创建一个表格容器5行4列, ?9 v3 J3 U3 R' c! N
- GtkWidget *table = gtk_table_new(5,4,TRUE);
+ w: W1 I) h- v9 i8 M; k
, ?: s' K D0 d- gtk_container_add(GTK_CONTAINER(window), table);4 F- I) Y$ \ J# Y
- ! v9 e$ ]1 J& U) Y4 g
- //创建一个行编辑
! h" `- W" h4 K% m/ M9 C0 H - GtkWidget *entry = gtk_entry_new();% [9 R) _& S! o, h* y
- 1 f. w* Z9 f" W- b
- gtk_entry_set_text(GTK_ENTRY(entry), "0");$ i& ~% [) R2 H$ B0 Q
0 d# J& w& H4 C- `" K3 b( Y; D) s- gtk_editable_set_editable(GTK_EDITABLE(entry), FALSE);) V. a# ?" t6 Q& A: Y$ c
- 8 G J# g: h5 _5 d
- //创建多个按钮
/ j- @4 O9 V$ L% J - GtkWidget *button0 = gtk_button_new_with_label("0");. G# g& [* X e* ?, W/ Q
- GtkWidget *button1 = gtk_button_new_with_label("1");
* b( v6 j% b4 T. G6 ^( Q5 t - GtkWidget *button2 = gtk_button_new_with_label("2");
1 g: p% l+ ^( l% @0 Y3 a) w - GtkWidget *button3 = gtk_button_new_with_label("3");) l' N8 O: o0 X }$ ]) e
- GtkWidget *button4 = gtk_button_new_with_label("4");
. D/ i% f; {3 E - GtkWidget *button5 = gtk_button_new_with_label("5");8 T" A0 V1 i- Z' S, C9 H8 L
- GtkWidget *button6 = gtk_button_new_with_label("6");4 _1 v! x& M( a& [
- GtkWidget *button7 = gtk_button_new_with_label("7");/ ]5 x% }( F0 i+ P$ b( r
- GtkWidget *button8 = gtk_button_new_with_label("8");) ~& c; s9 C# K+ m
- GtkWidget *button9 = gtk_button_new_with_label("9");
! S9 n' l1 @" |* U) Q( F2 C$ d -
4 g2 o$ C( B9 G2 ]. Q* z; N$ y3 g; E - GtkWidget *button_add = gtk_button_new_with_label("+");
4 _, ~: J" [& T8 B3 U - GtkWidget *button_minus = gtk_button_new_with_label("-");
+ n3 x9 i8 n# l, F/ l - GtkWidget *button_mul = gtk_button_new_with_label("*");
0 q4 Q! M, P0 y9 C, s3 _2 g - GtkWidget *button_div = gtk_button_new_with_label("/");
# R ~7 i) p3 j x$ K* M [% C1 i3 k - GtkWidget *button_equal = gtk_button_new_with_label("=");
& g3 N( ] I X# ?8 D1 d/ N - GtkWidget *button_delete = gtk_button_new_with_label("c");' ]8 R8 @4 s4 T+ }
- & o& N7 |+ j* H& q& P# F# E' l
2 ^( `- o8 _5 ?' i( n- gtk_table_attach_defaults(GTK_TABLE(table), entry, 0, 4, 0, 1);: @- x* v" ~# A' l4 K. q# R
- ' c. H6 a+ Z+ T% `
- gtk_table_attach_defaults(GTK_TABLE(table), button0, 0, 1, 4, 5);
0 ]+ V# G% B Y - gtk_table_attach_defaults(GTK_TABLE(table), button1, 0, 1, 3, 4);; x4 H2 v }5 \" P& H, Y
- gtk_table_attach_defaults(GTK_TABLE(table), button2, 1, 2, 3, 4);
' H9 i( g8 o5 E* F( w X - gtk_table_attach_defaults(GTK_TABLE(table), button3, 2, 3, 3, 4);) C. A: k' `7 _' M
- gtk_table_attach_defaults(GTK_TABLE(table), button4, 0, 1, 2, 3);! r6 W$ x( e0 X, t! h
- gtk_table_attach_defaults(GTK_TABLE(table), button5, 1, 2, 2, 3);
9 W4 L1 B$ u! D9 {; [ - gtk_table_attach_defaults(GTK_TABLE(table), button6, 2, 3, 2, 3);+ o) U+ ~5 Z$ j$ B. u/ S+ L& C$ [
- gtk_table_attach_defaults(GTK_TABLE(table), button7, 0, 1, 1, 2);+ a3 x6 V6 N# _6 R
- gtk_table_attach_defaults(GTK_TABLE(table), button8, 1, 2, 1, 2);4 l$ o% K1 T/ g, m9 D6 I' U" t
- gtk_table_attach_defaults(GTK_TABLE(table), button9, 2, 3, 1, 2);
( n% D; z+ O" q4 {# F9 P, c -
- F, w& }! L9 J - gtk_table_attach_defaults(GTK_TABLE(table), button_add, 1, 2, 4, 5);
6 {' Z( S7 K; E% {' p, v& ~ - gtk_table_attach_defaults(GTK_TABLE(table), button_minus, 2, 3, 4, 5);# N! m w! P& E T) a
- gtk_table_attach_defaults(GTK_TABLE(table), button_mul , 3, 4, 2, 3);
/ v, r5 c6 w. k0 G3 E - gtk_table_attach_defaults(GTK_TABLE(table), button_div, 3, 4, 3, 4);
4 M$ h$ U) |- ?5 k/ W - gtk_table_attach_defaults(GTK_TABLE(table), button_equal, 3, 4, 4, 5); e* Q5 G# ^7 L, M0 C
- gtk_table_attach_defaults(GTK_TABLE(table), button_delete, 3, 4, 1, 2);2 [3 w' H" g8 z! _
-
; T$ H; h: a& b# H9 G; V+ H; V - //注册信号函数,calc()' J- j# U+ [* h0 f& _6 {; I, J
- g_signal_connect(button0, "pressed", G_CALLBACK(calc), entry);
. [( M1 X# v2 r+ e0 u - g_signal_connect(button1, "pressed", G_CALLBACK(calc), entry);) D4 r0 Q' |" h7 ]/ G
- g_signal_connect(button2, "pressed", G_CALLBACK(calc), entry);/ w" K5 Y8 f; x* ?) _
- g_signal_connect(button3, "pressed", G_CALLBACK(calc), entry);) g( ]% Z V. s/ ?6 P
- g_signal_connect(button4, "pressed", G_CALLBACK(calc), entry);: b# Q2 b; V* O# n4 ~9 Z( n: J1 G
- g_signal_connect(button5, "pressed", G_CALLBACK(calc), entry);/ u( @/ k/ Q( m0 `: Y
- g_signal_connect(button6, "pressed", G_CALLBACK(calc), entry);2 @9 c7 [( {) }' G* [1 n
- g_signal_connect(button7, "pressed", G_CALLBACK(calc), entry);* [1 V/ r7 Z# l) a: j! k$ p9 \
- g_signal_connect(button8, "pressed", G_CALLBACK(calc), entry);
. R: z: ^0 M3 u+ m - g_signal_connect(button9, "pressed", G_CALLBACK(calc), entry);
& w2 w D/ {, a - & o" @2 k% s \6 S" }
- g_signal_connect(button_add, "pressed", G_CALLBACK(calc), entry);
4 `! |5 {) L* ]# @. a t! P7 x - g_signal_connect(button_mul, "pressed", G_CALLBACK(calc), entry);. y7 B3 q' b7 B4 t
- g_signal_connect(button_div, "pressed", G_CALLBACK(calc), entry);
, C3 E- I! v+ |8 ` - g_signal_connect(button_minus, "pressed", G_CALLBACK(calc), entry);( i6 I4 t7 {/ n2 S/ T9 J; |3 }8 i
- g_signal_connect(button_equal, "pressed", G_CALLBACK(calc), entry);% k- _1 \9 j; ~2 W& p& `4 A
- g_signal_connect(button_delete, "pressed", G_CALLBACK(calc), entry);
3 G6 R: W4 g1 L) v( r" G - , R: F6 t8 H- }# F7 ]
' y, Z |( Q+ `- N, D4 ^/ Z, X: z3 ~- gtk_widget_show_all(window);7 M) c* a1 z! y9 g! g
-
- {! l) F2 h% C7 I- ` - //主事件循环
4 O+ O }! u9 C" e - gtk_main();6 t4 w" J( T2 w, b- }
- ( X. q% S! s/ N3 p
- return 0;
# r G4 }7 U/ ?4 _, Z, s# ], p - }
复制代码 以上程序,编译运行后,就可以有以下得效果。 # p ]" ?/ V! y) G1 Y, B
+ f8 x+ e! m* l- O( m E7 |1 u
操作和UI都是比较简单得,就不演示过程了,系统得触摸驱动也是做好的,gtk只管做应用就好了。操作也算流畅,毕竟也没涉及到复杂的图表渲染。
* n! Q! Y# g/ j( F 搞到这里,发现其实不复杂得GUI程序用这套现成的框架倒也是挺方便。Linux系统下其实资源很丰富,软件开发方式也很多选择,所以不多做逗留了。这款开发板还有一大特点就是可以按照以往STM32单片机得方式进行使用,所以后面感受下1GHz的单片机开发方式。
& @* L- I; r! \# a/ K ?) B& _5 D3 B1 N" M3 l: d
|
官方板子不错,这么快就上手了。我的是odydess资料太少了。正在学习