linux开发板的软件开发三件套: 建立连接-->建立交叉编译环境-->建立驱动开发环境。
如果我们不涉及镜像的深度定制,只是平台化应用的话
1. 建立串口连接
查看手册, 获取接口定义说明:
板载一共两个端子,三个串口。
调试端口信息参照快速指南,用原配的USB-TTL线缆连接电脑(看驱动应该是用的CH340):
调试R5内核,就连接上面的UART3,另外一节说明。
调试工具还是我们经典的secureCRT,连接好后,设置串口速率115200, 选择正确的串口建立连接:
最好重新复位一下,登录用户root, 初始无密码,可以用passwd命令设置密码:
小核R5核可以通过另外个串口连接RTOS进行开发, 但没看到详细文档, 在评估手册里有一句“如需深入了解异构多核通信方式的实现,请阅读应用笔记《MYD-JD9X R5 协处理器
应用开发笔记》。”, 这个应用笔记暂时还没找到,确认串口连接后,只能放一放。
串口连到J6:
>help
>
help:Lists all the registered commands>
sleepm: sleep number of millisecondssleepm 1000
>
sleep: sleep number of secondssleep 5
>
chain:chain load another binary>
stackstomp:intentionally overrun the stack>
crash:intentionally crash>
mc:copy a range of memory>
fb:fill range of memory by byte>
fh:fill range of memory by halfword>
fw:fill range of memory by word>
mb:modify byte of memory>
mh:modify halfword of memory>
mw:modify word of memory>
db:display memory in bytes>
dh:display memory in halfwords>
dw:display memory in words>
task-stats:Showing the state of RTOS task>
应该是RTOS的系统调试命令,其中并没有手册上的GPIO命令,待找到文档后另文记录。
2. 对照手册熟悉板载资源和命令:
2. 1查看CPU信息:
root@myd-jd9x:~# cat /proc/cpuinfo
processor : 0
BogoMIPS : 6.00
Features : fp asimd evtstrm crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x2
CPU part : 0xd05
CPU revision : 0processor : 1
BogoMIPS : 6.00
Features : fp asimd evtstrm crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x2
CPU part : 0xd05
CPU revision : 0processor : 2
BogoMIPS : 6.00
Features : fp asimd evtstrm crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x2
CPU part : 0xd05
CPU revision : 0processor : 3
BogoMIPS : 6.00
Features : fp asimd evtstrm crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x2
CPU part : 0xd05
CPU revision : 0
查看CPU温度:
root@myd-jd9x:~# cat /sys/class/thermal/thermal_zone0/temp
42000
2.2 查看系统RTC,设置系统时间
RTC(Real-time clock)本身是一个时钟,用来记录真实时间,当软件系统关机后
保留系统时间并继续进行计时,系统重新开启后在将时间同步进软件系统。
JD9X 芯片内部包含 RTC 时钟,如果实际产品对 RTC 功耗要求不是很高,对断电时间
保持要求在一个月以内,可以直接使用芯片内部 RTC,否则就需要采用专用外部 RTC 芯
片了。RTC 的测试通常采用 Linux 系统常用的 hwclock 和 date 命令配合进行,下面测试
将系统时间写入 RTC,读取 RTC 时间并设置为系统时间并进行时间掉电保持的测试。
查看设备:
root@myd-jd9x:/mnt/mmc# ls /dev/rtc* -al
lrwxrwxrwx 1 root root 4 Jan 1 00:00 /dev/rtc -> rtc0
crw------- 1 root root 250, 0 Jan 1 00:00 /dev/rtc0
crw------- 1 root root 250, 1 Jan 1 00:00 /dev/rtc1
查看及设置系统时间:
root@myd-jd9x:/mnt/mmc# date
Fri Jan 1 01:55:16 UTC 2066
root@myd-jd9x:/mnt/mmc# date 100311332023.10
Tue Oct 3 11:33:10 UTC 2023
设置系统时间格式: YYDDHHMMYYYY.SS
此时设置的系统时间掉电不会保存,可以用hwclock命令查看、写入、再去人RTC设备的系统时钟:
root@myd-jd9x:/mnt/mmc# hwclock
Fri Jan 1 01:58:07 2066 0.000000 seconds
root@myd-jd9x:/mnt/mmc# hwclock -w
root@myd-jd9x:/mnt/mmc# hwclock -r
Tue Oct 3 11:35:43 2023 0.000000 seconds
root@myd-jd9x:/mnt/mmc# hwclock
Tue Oct 3 11:35:48 2023 0.000000 seconds
2.3 查看内存:
root@myd-jd9x:~# cat /proc/meminfo
MemTotal: 1646188 kB
MemFree: 1218344 kB
MemAvailable: 1353540 kB
Buffers: 6272 kB
Cached: 283548 kB
SwapCached: 0 kB
Active: 52676 kB
Inactive: 274908 kB
Active(anon): 37892 kB
Inactive(anon): 1164 kB
Active(file): 14784 kB
Inactive(file): 273744 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 35888 kB
Mapped: 45416 kB
Shmem: 1288 kB
Slab: 37956 kB
SReclaimable: 19988 kB
SUnreclaim: 17968 kB
KernelStack: 2080 kB
PageTables: 632 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 823092 kB
Committed_AS: 103868 kB
VmallocTotal: 135290290112 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
AnonHugePages: 18432 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
CmaTotal: 262144 kB
CmaFree: 240888 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
看懂参数
MemTotal
:所有可用的 RAM 大小,物理内存减去预留位和内核使用
MemFree
:LowFree + HighFree
Buffers
:用来给块设备做缓存的大小
Cached
:文件的缓冲区大小
SwapCached
:已经被交换出来的内存。与 I/O 相关
Active
:经常(最近)被使用的内存
Inactive
:最近不常使用的内存
系统内置了memtester工具,可以做压测:
root@myd-jd9x:~# memtester
memtester version 4.5.0 (64-bit)
Copyright (C) 2001-2020 Charles Cazabon.
Licensed under the GNU General Public License version 2 (only).pagesize is 4096
pagesizemask is 0xfffffffffffff000
need memory argument, in MBUsage: memtester [-p physaddrbase [-d device]] <mem>[B|K|M|G] [loops]
测试看看:
root@myd-jd9x:~# memtester 300M 1
memtester version 4.5.0 (64-bit)
Copyright (C) 2001-2020 Charles Cazabon.
Licensed under the GNU General Public License version 2 (only).pagesize is 4096
pagesizemask is 0xfffffffffffff000
want 300MB (314572800 bytes)
got 300MB (314572800 bytes), trying mlock ...locked.
Loop 1/1:Stuck Address : ok Random Value : okCompare XOR : okCompare SUB : okCompare MUL : okCompare DIV : okCompare OR : okCompare AND : okSequential Increment: okSolid Bits : ok Block Sequential : ok Checkerboard : ok Bit Spread : ok Bit Flip : ok Walking Ones : ok Walking Zeroes : ok 8-bit Writes : ok16-bit Writes : okDone.
2.3查看EMMC, 测试读写速度
root@myd-jd9x:/mnt/mmc# fdisk -l
Found valid GPT with protective MBR; using GPTDisk /dev/mmcblk0: 30777344 sectors, 2740M
Logical sector size: 512
Disk identifier (GUID): 4ad76685-a1da-474a-8041-154d90f10ef7
Partition table holds up to 128 entries
First usable sector is 4096, last usable sector is 30777310Number Start (sector) End (sector) Size Name1 4096 4607 256K dil2_a2 4608 5119 256K dil2_b3 5120 6143 512K ddr_init_seq_a4 6144 7167 512K ddr_init_seq_b5 7168 8191 512K ddr_fw_a6 8192 9215 512K ddr_fw_b7 9216 9247 16384 ddr_ioretention8 9248 9503 128K system_config_a9 9504 9759 128K system_config_b10 9760 10783 512K ssystem_a11 10784 11807 512K ssystem_b12 11808 11935 65536 hsm_fw_a13 11936 12063 65536 hsm_fw_b14 12064 13087 512K preloader_a15 13088 14111 512K preloader_b16 14112 18207 2048K safety_os_a17 18208 22303 2048K safety_os_b18 22304 71455 24.0M res_a19 71456 120607 24.0M res_b20 120608 120863 128K atf_a21 120864 121119 128K atf_b22 121120 125215 2048K tos_a23 125216 129311 2048K tos_b24 129312 129439 65536 vbmeta_a25 129440 129567 65536 vbmeta_b26 129568 133663 2048K bootloader_a27 133664 137759 2048K bootloader_b28 137760 137887 65536 env_a29 137888 138015 65536 env_b30 138016 12720927 6144M rootfs31 12720928 16915231 2048M backup32 16915232 16980767 32.0M sdrv_update33 16980768 16981791 512K dtb_a34 16981792 16982815 512K dtb_b35 16982816 16983839 512K dtbo_a36 16983840 16984863 512K dtbo_b37 16984864 17042207 28.0M kernel_a38 17042208 17099551 28.0M kernel_b39 17099552 17623839 256M data40 17623840 30777310 6422M userdata
Disk /dev/mmcblk0rpmb: 4 MB, 4194304 bytes, 8192 sectors
128 cylinders, 4 heads, 16 sectors/track
Units: sectors of 1 * 512 = 512 bytesDisk /dev/mmcblk0rpmb doesn't contain a valid partition table
Disk /dev/mmcblk0boot1: 4 MB, 4194304 bytes, 8192 sectors
128 cylinders, 4 heads, 16 sectors/track
Units: sectors of 1 * 512 = 512 bytesDisk /dev/mmcblk0boot1 doesn't contain a valid partition table
Disk /dev/mmcblk0boot0: 4 MB, 4194304 bytes, 8192 sectors
128 cylinders, 4 heads, 16 sectors/track
Units: sectors of 1 * 512 = 512 bytesDisk /dev/mmcblk0boot0 doesn't contain a valid partition table
Disk /dev/mmcblk2: 29 GB, 31266439168 bytes, 61067264 sectors
3801 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytesDevice Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/mmcblk2p1 0,130,3 1023,254,63 8192 61067263 61059072 29.1G 7 HPFS/NTFS
df命令查看分区信息
root@myd-jd9x:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 1.9G 1.4G 353.4M 81% /
devtmpfs 659.1M 0 659.1M 0% /dev
tmpfs 803.8M 0 803.8M 0% /dev/shm
tmpfs 803.8M 128.0K 803.7M 0% /tmp
tmpfs 803.8M 408.0K 803.4M 0% /run
izone命令测试读写速度:
root@myd-jd9x:~# iozone -e -I -a -s 100M -r 1M -i 0 -i 1 -i 2Iozone: Performance Test of File I/OVersion $Revision: 3.489 $Compiled for 64 bit mode.Build: linux Contributors:William Norcott, Don Capps, Isom Crawford, Kirby CollinsAl Slater, Scott Rhine, Mike Wisner, Ken GossSteve Landherr, Brad Smith, Mark Kelly, Dr. Alain CYR,Randy Dunlap, Mark Montague, Dan Million, Gavin Brebner,Jean-Marc Zucconi, Jeff Blomberg, Benny Halevy, Dave Boone,Erik Habbinga, Kris Strecker, Walter Wong, Joshua Root,Fabrice Bacchella, Zhenghua Xue, Qin Li, Darren Sawyer,Vangel Bojaxhi, Ben England, Vikentsi Lapa,Alexey Skidanov, Sudhir Kumar.Run began: Tue Oct 3 11:49:24 2023Include fsync in write timingO_DIRECT feature enabledAuto ModeFile size set to 102400 kBRecord Size 1024 kBCommand line used: iozone -e -I -a -s 100M -r 1M -i 0 -i 1 -i 2Output is in kBytes/secTime Resolution = 0.000001 seconds.Processor cache size set to 1024 kBytes.Processor cache line size set to 32 bytes.File stride size set to 17 * record size.random random bkwd record stride kB reclen write rewrite read reread read write read rewrite read fwrite frewrite fread freread102400 1024 81469 82252 259652 270079 253454 81344 iozone test complete.
测试结果: 读--253Mbps, 写--81Mbps
2.4 查看SD卡, 挂载分区, 测试读写速度
上面fdisk命令有列出sd卡的分区信息:
Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/mmcblk2p1 0,130,3 1023,254,63 8192 61067263 61059072 29.1G 7 HPFS/NTFS
注意,如果提示信息是windows系统的话,可以在PC上用读卡器重新格式化NTFS格式。
新建目录,并挂载分区,查看:
root@myd-jd9x:~# mount /dev/mmcblk2p1 /mmc
root@myd-jd9x:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 1.9G 1.4G 353.4M 81% /
devtmpfs 659.1M 0 659.1M 0% /dev
tmpfs 803.8M 0 803.8M 0% /dev/shm
tmpfs 803.8M 124.0K 803.7M 0% /tmp
tmpfs 803.8M 408.0K 803.4M 0% /run
/dev/mmcblk2p1 29.1G 63.5M 29.1G 0% /mmc
此时目录/mmc为只读属性
root@myd-jd9x:~# cd /mmc
root@myd-jd9x:/mmc# ls
System Volume Information
root@myd-jd9x:/mmc# mkdir temp
mkdir: can't create directory 'temp': Read-only file system
在目录下操作,就可以读写了
root@myd-jd9x:/mmc# mount /dev/mmcblk2p1 /mmc
root@myd-jd9x:/mmc# ls
root@myd-jd9x:/mmc# mkdir temp
root@myd-jd9x:/mmc# ls
temp
root@myd-jd9x:/mmc# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 1.9G 1.4G 353.4M 81% /
devtmpfs 659.1M 0 659.1M 0% /dev
tmpfs 803.8M 0 803.8M 0% /dev/shm
tmpfs 803.8M 128.0K 803.7M 0% /tmp
tmpfs 803.8M 408.0K 803.4M 0% /run
/dev/mmcblk2p1 29.1G 63.5M 29.1G 0% /mmc
遗留问题--怎么开机自动挂载还没解决,编辑/etc/fstab方法没起作用
测试读写速度:
root@myd-jd9x:/mmc# iozone -e -I -a -s 100M -r 1M -i 0 -i 1Iozone: Performance Test of File I/OVersion $Revision: 3.489 $Compiled for 64 bit mode.Build: linux Contributors:William Norcott, Don Capps, Isom Crawford, Kirby CollinsAl Slater, Scott Rhine, Mike Wisner, Ken GossSteve Landherr, Brad Smith, Mark Kelly, Dr. Alain CYR,Randy Dunlap, Mark Montague, Dan Million, Gavin Brebner,Jean-Marc Zucconi, Jeff Blomberg, Benny Halevy, Dave Boone,Erik Habbinga, Kris Strecker, Walter Wong, Joshua Root,Fabrice Bacchella, Zhenghua Xue, Qin Li, Darren Sawyer,Vangel Bojaxhi, Ben England, Vikentsi Lapa,Alexey Skidanov, Sudhir Kumar.Run began: Fri Jan 1 00:23:55 2066Include fsync in write timingO_DIRECT feature enabledAuto ModeFile size set to 102400 kBRecord Size 1024 kBCommand line used: iozone -e -I -a -s 100M -r 1M -i 0 -i 1Output is in kBytes/secTime Resolution = 0.000001 seconds.Processor cache size set to 1024 kBytes.Processor cache line size set to 32 bytes.File stride size set to 17 * record size.random random bkwd record stride kB reclen write rewrite read reread read write read rewrite read fwrite frewrite fread freread102400 1024 81814 81549 244964 254929 iozone test complete.
3. 建立网络连接,方便文件传输
首先在PC端配置网口为固定IP(windows为例):
在开发板,先查看所有网络设备:
root@myd-jd9x:~# ifconfig -a
can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 NOARP MTU:16 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:10 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)Interrupt:47 can1 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 NOARP MTU:16 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:10 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)Interrupt:48 eth0 Link encap:Ethernet HWaddr DA:8D:4E:34:29:06 BROADCAST MULTICAST MTU:1500 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)Interrupt:42 eth1 Link encap:Ethernet HWaddr F2:37:37:90:2E:7D BROADCAST MULTICAST MTU:1500 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)Interrupt:43 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING MTU:65536 Metric:1RX packets:2472 errors:0 dropped:0 overruns:0 frame:0TX packets:2472 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:182912 (178.6 KiB) TX bytes:182912 (178.6 KiB)mlan0 Link encap:Ethernet HWaddr 5C:C5:63:4F:65:50 BROADCAST MULTICAST MTU:1500 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)p2p0 Link encap:Ethernet HWaddr 5E:C5:63:4F:65:50 BROADCAST MULTICAST MTU:1500 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)tunl0 Link encap:UNSPEC HWaddr 00-00-00-00-30-30-00-30-00-00-00-00-00-00-00-00 NOARP MTU:1480 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)uap0 Link encap:Ethernet HWaddr 5C:C5:63:4F:66:50 BROADCAST MULTICAST MTU:1500 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
配置打开以太网口,并配置固定IP, 分别把两个网口固定IP设置为192.168.0.101和192.168.0.102, 并互拼一下:
root@myd-jd9x:~# ifconfig eth1 192.168.0.102 netmask 255.255.255.0 up
root@myd-jd9x:~# ifconfig
eth0 Link encap:Ethernet HWaddr DA:8D:4E:34:29:06 inet addr:192.168.0.101 Bcast:192.168.0.255 Mask:255.255.255.0UP BROADCAST MULTICAST MTU:1500 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)Interrupt:42 eth1 Link encap:Ethernet HWaddr F2:37:37:90:2E:7D inet addr:192.168.0.102 Bcast:192.168.0.255 Mask:255.255.255.0UP BROADCAST MULTICAST MTU:1500 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)Interrupt:43 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING MTU:65536 Metric:1RX packets:2631 errors:0 dropped:0 overruns:0 frame:0TX packets:2631 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:195856 (191.2 KiB) TX bytes:195856 (191.2 KiB)root@myd-jd9x:~# ping 192.168.0.102
PING 192.168.0.102 (192.168.0.102): 56 data bytes
64 bytes from 192.168.0.102: seq=0 ttl=64 time=0.916 ms
64 bytes from 192.168.0.102: seq=1 ttl=64 time=0.793 ms
64 bytes from 192.168.0.102: seq=2 ttl=64 time=1.175 ms
上位机在命令行下ping下开发板,确认可以连接:
为了方便后续加载传输可执行文件,下载安装filezilla进行ftp连接, 然后打开,连接开发板, 输入用户root,密码admin(或自己设定的其他密码),端口22, 连接成功:
基本特性及连接配置完成,下一节开始编程测试。