1 开发板介绍
1.1 外设
1.2 特性
1.3 块表
1.4 AUDIO硬件原理
2 开发环境搭建(GCC方式)
PC环境:win10
NuMaker-IoT-M487 上手指南
2.1 Env RT-Thread 开发辅助工具
env_released_1.2.0.7z
解压后即可打开env.bat或env.exe即可使用(注意解压路径里最好不能有中文和空格)
2.2 安装Nu-Linker驱动
Nu-Link_IAR 驱动里有Nu-Link_USB_Driver 1.8.exe这个驱动安装文件。
装完驱动后,使用 USB 线连接开发板的 USB ICE Connector 到 PC 机,会检测到COM口,如下图:
2.3 源码获取
Administrator@BKL85SWJMT1GA7J E:\NuMaker
git clone https://gitee.com/rtthread/rt-thread.git
Cloning into 'rt-thread'...
remote: Enumerating objects: 187653, done.
remote: Counting objects: 100% (13282/13282), done.
remote: Compressing objects: 100% (6418/6418), done.
remote: Total 187653 (delta 8657), reused 9783 (delta 6665), pack-reused 174371
Receiving objects: 100% (187653/187653), 524.46 MiB | 3.55 MiB/s, done.
Resolving deltas: 100% (134067/134067), done.
Updating files: 100% (28432/28432), done.
2.4 下载项目(NuMaker-IoT-M487)相关套件
cd bsp\nuvoton\numaker-iot-m487: 切换到numaker-iot-m487的工作目录;
menuconfig --generate: 根据.config生成rtconfig.h文件;
pkgs --update: 从git repo上更新本地包和Env脚本(应该时根据.config文件);
menuconfig可以修改整个工程配置;
pkgs —printenv也很有用,可以查看Env的环境变量;
Administrator@BKL85SWJMT1GA7J E:\NuMaker
cd bsp\nuvoton\numaker-iot-m487
Administrator@BKL85SWJMT1GA7J E:\NuMaker\rt-thread\bsp\nuvoton\numaker-iot-m487
menuconfig --generate
Administrator@BKL85SWJMT1GA7J E:\NuMaker\rt-thread\bsp\nuvoton\numaker-iot-m487
pkgs --update
Cloning into 'E:\NuMaker\rt-thread\bsp\nuvoton\numaker-iot-m487\packages\at_device-latest'...
remote: Enumerating objects: 1647, done.
remote: Counting objects: 100% (150/150), done.
remote: Compressing objects: 100% (138/138), done.
remote: Total 1647 (delta 80), reused 39 (delta 8), pack-reused 1497R
Receiving objects: 100% (1647/1647), 689.47 KiB | 222.00 KiB/s, done.
Resolving deltas: 100% (1050/1050), done.
==============================> AT_DEVICE latest is downloaded successfully.
==============================> at_device update done
Operation completed successfully.
2.5 GCC 编译项目
Env RT-Thread环境中已有arm-none-eabi交叉编译链;
scons进行自动构建,生成rtthread.bin
2.5.1 检测交叉编译链工具
env_released_1.2.0\env
arm-none-eabi-
arm-none-eabi-addr2line.exe arm-none-eabi-gcc-nm.exe arm-none-eabi-nm.exe
arm-none-eabi-ar.exe arm-none-eabi-gcc-ranlib.exe arm-none-eabi-objcopy.exe
arm-none-eabi-as.exe arm-none-eabi-gcc.exe arm-none-eabi-objdump.exe
arm-none-eabi-c++.exe arm-none-eabi-gcov-tool.exe arm-none-eabi-ranlib.exe
arm-none-eabi-c++filt.exe arm-none-eabi-gcov.exe arm-none-eabi-readelf.exe
arm-none-eabi-cpp.exe arm-none-eabi-gdb-py.exe arm-none-eabi-size.exe
arm-none-eabi-elfedit.exe arm-none-eabi-gdb.exe arm-none-eabi-strings.exe
arm-none-eabi-g++.exe arm-none-eabi-gprof.exe arm-none-eabi-strip.exe
arm-none-eabi-gcc-5.4.1.exe arm-none-eabi-ld.bfd.exe
arm-none-eabi-gcc-ar.exe arm-none-eabi-ld.exe
2.5.2 scons构建
注意:一定要切到项目下构建(rt-thread\bsp\nuvoton\numaker-iot-m487)
scons
scons: Reading SConscript files ...
Newlib version:2.4.0
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build
CC build\applications\main.o
CC build\applications\mnt.o
CC build\board\board_dev.o
CC build\board\NuClockConfig\nutool_modclkcfg.o
CC build\board\NuPinConfig\nutool_pincfg.o
此处打印太多省略
CC E:\NuMaker\rt-thread\bsp\nuvoton\libraries\nu_packages\AudioCodec\audio_test.o
CC E:\NuMaker\rt-thread\bsp\nuvoton\libraries\nu_packages\AudioCodec\acodec_nau88l25.o
CC E:\NuMaker\rt-thread\bsp\nuvoton\libraries\nu_packages\BMX055\libraries\BMG160_driver\bmg160.o
CC E:\NuMaker\rt-thread\bsp\nuvoton\libraries\nu_packages\BMX055\libraries\BMA2x2_driver\bma2x2.o
CC E:\NuMaker\rt-thread\bsp\nuvoton\libraries\nu_packages\BMX055\sensor_bmx055.o
CC E:\NuMaker\rt-thread\bsp\nuvoton\libraries\nu_packages\BMX055\libraries\BMM050_driver\bmm050.o
CC E:\NuMaker\rt-thread\bsp\nuvoton\libraries\nu_packages\Demo\usbd_cdc_vcom_echo.o
CC E:\NuMaker\rt-thread\bsp\nuvoton\libraries\nu_packages\Demo\slcd_show_tick.o
CC E:\NuMaker\rt-thread\bsp\nuvoton\libraries\nu_packages\Demo\usbd_hid_dance_mouse.o
LINK rtthread.elf
arm-none-eabi-objcopy -O binary rtthread.elf rtthread.bin
arm-none-eabi-size rtthread.elf
text data bss dec hex filename
277116 5080 57760 339956 52ff4 rtthread.elf
scons: done building targets.
3 开发板烧录
主要烧录方式两种:
NuMicro MCU 虚拟磁盘;
RT-Thread Studio工具烧录。
这里用的是NuMicro MCU 虚拟磁盘方式,区别是要将NuMaker-IoT-M487 上的 ISW1四个开关都拨到 ‘ON’ 的位置;而RT-Thread Studio工具烧录则是ISW1前三个开关拨到 ‘ON’,第四个开关要拨到 ‘OFF’。
NuMicro MCU 虚拟磁盘的ISW1四个开关状态如下图:
配置完成后,将开发板使用 Micro USB 连接线连接计算机,我的计算机将出现一个 NuMicro MCU 虚拟磁盘。
将上一步编译出的rtthread.bin拷贝到该虚拟磁盘根目录,然后NuMaker M487会自动检测、升级和重启。
-
RT - Thread Operating System
/ | \ 4.1.0 build Apr 7 2022 22:24:56
2006 - 2022 Copyright by RT-Thread team
This chip does not support TRNG!
[I/I2C] I2C bus [i2c0] registered
[I/I2C] I2C bus [i2c1] registered
[I/I2C] I2C bus [i2c2] registered
[W/drv.qspi] qspi0 clock max frequency is 48000000Hz (!= 50000000Hz)
[I/SFUD] Find a Winbond flash chip. Size is 4194304 bytes.
[I/SFUD] flash0 flash device is initialize success.
[I/SFUD] Probe SPI flash flash0 by SPI device qspi01 success.
[I/sal.skt] Socket Abstraction Layer initialize success.
[I/utest] utest is initialize success.
[I/utest] total utest testcase num: (0)
Failed to mount elm on /.
Try to execute 'mkfs -t elm flash0' first, then reboot.
[I/at.clnt] AT client(V1.3.1) on device uart1 initialize success.
[I/sensor] rt_sensor[mag_bmx055] init success
[I/sensor] rt_sensor[acce_bmx055] init success
[I/sensor] rt_sensor[gyro_bmx055] init success
[D/FAL] (fal_flash_init:49) Flash device | OnChip_APROM | addr: 0x00000000 | len: 0x00080000 | blk_size: 0x00001000 |initialized finish.
[D/FAL] (fal_flash_init:49) Flash device | OnChip_LDROM | addr: 0x00100000 | len: 0x00101000 | blk_size: 0x00001000 |initialized finish.
[I/FAL] ==================== FAL partition table ====================
[I/FAL] | name | flash_dev | offset | length |
[I/FAL] -------------------------------------------------------------
[I/FAL] | ldrom | OnChip_LDROM | 0x00000000 | 0x00001000 |
[I/FAL] | aprom | OnChip_APROM | 0x00060000 | 0x00020000 |
[I/FAL] =============================================================
[I/FAL] RT-Thread Flash Abstraction Layer initialize success.
[I/dancemouse] Ready.
msh />[I/at.dev.esp] esp0 device wifi is disconnect.
msh />[E/at.clnt] execute command (AT+CWJAP="NT_ZY_BUFFALO","12345678") failed!
[W/at.dev.esp] esp0 device wifi connect failed, check ssid(NT_ZY_BUFFALO) and password(12345678).
[I/at.dev.esp] esp0 device network initialize successfully.
[E/at.clnt] execute command (AT+CWJAP=”NT_ZY_BUFFALO”,”12345678”) failed!表示wifi的ssid和密码不对!
4 AUDIO测试
4.1 wavpayer组件
进入menuconfig界面,选择wavpayer组件
.config - RT-Thread Configuration
→ RT-Thread online packages
→ multimedia packages
→ WavPlayer: Minimal music player for wav file play and record ─
┌──────────────────────────────────────────────────┐
│ --- WavPlayer: Minimal music player for wav file play and record │
│ [ *] Enable support for play (NEW) │
│ (sound0) The play device name (NEW) │
│ [* ] Enable support for record │
│ (sound0) The record device name (NEW) │
│ Version (latest) ---> │
└──────────────────────────────────────────────────┘
├──────────────────────────────────────────────────┤
│ < Exit > < Help > < Save > < Load > │
└──────────────────────────────────────────────────┘
更新组件到本地
pkgs --update
重新编译,生成rtthread.bin
scons
将生成的rtthread.bin用虚拟磁盘方式烧录进去,可以看到有wavplay和wavrecord命令:
msh />wavplay -h
usage: wavplay [option] [target] ...
usage options:
-h, --help Print defined help message.
-s URI, --start=URI Play wav music with URI(local files).
-t, --stop Stop playing music.
-p, --pause Pause the music.
-r, --resume Resume the music.
-v lvl, --volume=lvl Change the volume(0~99).
-d, --dump Dump play relevant information.
msh />wavrecord -h
usage: wavrecord [option] [target] ...
usage options:
-h, --help Print defined help message.
-s file --start=file
record wav music to filesystem.
-t, --stop Stop record.
4.2 挂载elm文件系统
wavrecord录制wav文件到文件系统上,elm是fatfs文件系统。
msh />mkfs -t elm flash0
msh />mount flash0 / elm
mount device flash0(elm) onto / ... succeed!
msh />mount
filesystem device mountpoint
devfs (NULL) /dev
elm flash0 /
mkfs -t elm flash0: 对设备flash0制作elm文件系统
mount flash0 / elm: 挂载设备flash0到/节点上,该设备是elm文件系统
4.3 录音测试
wavrecord -s /test.wav 8000 2 16: 开始录音,PCM格式为采样率8K/双通道/16bit精度,封装格式为WAV。
wavrecord -t:停止录音
演示:
msh />wavrecord -s /test.wav 8000 2 16
[I/i2s] Stop record.
[I/i2s] Close I2S.
[I/acodec.nau88l25] Software Reset.
[I/acodec.nau88l25] Initialized done.
[I/i2s] Open I2S.
[W/i2s] Real sample rate: 46875 Hz != preferred sample rate: 48000 Hz
[I/i2s] Start record.
Information:
samplerate 8000
channels 2
[I/i2s] Stop record.
[I/i2s] Close I2S.
[I/acodec.nau88l25] Software Reset.
[I/acodec.nau88l25] Initialized done.
[I/i2s] Open I2S.
[W/i2s] Real sample rate: 8152 Hz != preferred sample rate: 8000 Hz
[I/i2s] Start record.
msh />
msh />wavrecord -t
[I/i2s] Stop record.
[I/i2s] Close I2S.
msh />ls
Directory /:
test.wav 442412
通过ls命令查看到test.wav文件。
4.4 播放测试
播放录音文件test.wav
wavplay -s /test.wav: 开始播放test.wav文件,wav封装头中有音频的采样率/通道/精度,不用再指定这些参数;
演示:
msh />wavplay -s /test.wav
[I/WAV_PLAYER] play start, uri=/test.wav
[I/i2s] Stop replay.
[I/i2s] Close I2S.
[I/acodec.nau88l25] Software Reset.
[I/acodec.nau88l25] Initialized done.
[I/i2s] Open I2S.
[W/i2s] Real sample rate: 8152 Hz != preferred sample rate: 8000 Hz
[I/i2s] Start replay.
[I/i2s] Stop replay.
[I/i2s] Close I2S.
[I/WAV_PLAYER] play end
这里可以手动在发命令结束播放,也可以等待播放完毕。
wavplay -t: 结束播放;
演示:
msh />wavplay -s /test.wav
[I/WAV_PLAYER] play start, uri=/test.wav
[I/i2s] Stop replay.
[I/i2s] Close I2S.
[I/acodec.nau88l25] Software Reset.
[I/acodec.nau88l25] Initialized done.
[I/i2s] Open I2S.
[W/i2s] Real sample rate: 8152 Hz != preferred sample rate: 8000 Hz
[I/i2s] Start replay.
msh />wavplay -t
[I/i2s] Stop replay.
[I/i2s] Close I2S.
[I/WAV_PLAYER] play end
wavplay -v 70: 在正在播放时,可以调节音量,比如70
msh />wavplay -v 70
[I/WAV_PLAYER] set volume = 70
这里有”[I/WAV_PLAYER] set volume = 70”这句打印需要修改wavplayer.c中wavplayer_volume_set里的打印LOG_D为LOG_I。
wavplay -p: 暂停播放;
wavplay -r: 恢复播放;
5 测试结果
这里总体音频测试结果不是很理想,主要现象表现为播放时有时声音时正常的,有时都是全是噪音或变调;
参数
结果(测十次)
测试命令
8000/1/16
3次有声音(环境噪明显), 7次全噪
wavrecord -s 8000_1.wav 8000 1; wavrecord -t; wavplay -s 8000_1.wav
8000/2/16
6次正常,4次全是噪声
wavrecord -s 8000_2.wav 8000 2; wavrecord -t; wavplay -s 8000_2.wav
16000/1/16
5次正常,5次全是噪声
wavrecord -s 16000_1.wav 16000 1; wavrecord -t; wavplay -s 16000_1.wav
16000/2/16
5次正常,5次全是噪声
wavrecord -s 16000_2.wav 16000 2; wavrecord -t; wavplay -s 16000_2.wav
44100/1/16
5次变调加噪声,5次全是噪声
wavrecord -s 44100_1.wav 44100 1; wavrecord -t; wavplay -s 44100_1.wav
44100/2/16
5次变调,5次全是噪声
wavrecord -s 44100_2.wav 44100 2; wavrecord -t; wavplay -s 44100_2.wav
48000/1/16
1次变调加噪声,9次全是噪声
wavrecord -s 48000_1.wav 48000 1; wavrecord -t; wavplay -s 48000_1.wav
48000/2/16
1次变调加噪声,9次全是噪声
wavrecord -s 48000_2.wav 48000 2; wavrecord -t; wavplay -s 48000_2.wav
原作者:rt_wei