NXP

基于NXP Vybrid ARM处理器部署MQX实时操作系统

2019-07-12 11:33发布

1). 简介 MQX是由NXP提供的实时操作系统,结构框图如下图所示, 包含内核,文件系统以及协议栈, 同时对于NXP的ARM处理器也可以很好的支持,可以很方便的开发和部署.
本文就基于Toradex Colibri VF61 (基于NXP VF61 SoC) ARM计算机模块搭配Colibri Eva Board开发板来演示编译和部署MQX应用. VF61为异构双核架构ARM处理器,包含一个Cortex-A5和一个Cortex-M4,通常应用场景为A5核心运行Linux或者WinCE系统作为控制和界面显示,M4核心运行一个实时操作系统来处理实时任务. 本文所演示的即是在M4核心上面部署运行MQX应用. 2). 准备 a). 硬件准备 ./ Colibri VF61计算机模块和Colibri Eva Board开发板 ./ Ubuntu Linux开发主机 b). 软件准备 ./ VF61模块A5核心运行Toradex Embedded Linux release V2.5 Beta3 ./ Ubuntu Linux开发主机 ./ MQX RTOS 4.1.2 Vybrid - 从这里下载 ./ Linaro bare-metal toolchain for Cortex-R/M, 4.8 2014-Q1 update - 从这里下载 3). 配置 a). 解压缩到”/home/username”目录下 ------------------------ $ tar xzf “~/MQX RTOS 4.1.2 for Vybrid Linux Base.gz.gz” $ tar xjf ~/gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2 ------------------------ b). 配置MQX ./ 文件 ”FSLMQXOS_4_1_2_Vybrid/build/common/make/global.mak” 设置交叉编译toolchain ------------------------ + TOOLCHAIN_ROOTDIR = /home/yourname/gcc-arm-none-eabi-4_8-2014q3/ ------------------------   ./ 文件  “FSLMQXOS_4_1_2_Vybrid/config/twrvf65gs10_m4/user_config.h” 由于VF61 A5和M4共享外设资源,因此在使用M4外设时候要通过修改A5 Device Tree来确保此外设没有被A5已经占用.本文后续只测试M4调用GPIO,因此将其他和A5冲突的外设资源都去掉,实际应用中可以根据具体情况做配置. ------------------------ ... #define BSPCFG_ENABLE_I2C0                  0 #define BSPCFG_ENABLE_II2C0                  0 ... #define BSPCFG_ENABLE_SPI0                   0 ... #define BSPCFG_ENABLE_RTCDEV               0 ... #define BSPCFG_ENABLE_ESDHC                0 #define BSPCFG_ENABLE_SAI                    0 ... #define BSPCFG_ENABLE_TTYB                   0 #define BSPCFG_ENABLE_ITTYB                  0   #define BSPCFG_ENABLE_TTYC                   1 #define BSPCFG_ENABLE_ITTYC                   0 ... ------------------------   ./ 文件 ”FSLMQXOS_4_1_2_Vybrid/mqx/source/bsp/twrvf65gs10_m4/twrvf65gs10_m4.h” 修改时钟 ------------------------ ... #define BSP_CORE_CLOCK                  (166700000) #define BSP_BUS_CLOCK                   (166700000) #define BSP_SYSTEM_CLOCK                (83300000) #define BSP_IPG_CLOCK                   (83300000) ... ------------------------ 4). 编译MQX a). 替换  “mqx/examples/hello/build/make/hello_twrvf65gs10_m4/build_gcc_arm.sh” 文件 从这里下载文件 b). 编译Helloworld Firmware ------------------------ $ cd mqx/examples/hello/build/make/hello_twrvf65gs10_m4/ $ ./build_gcc_arm.sh ... Build done Press any key to continue... ------------------------ c). 创建binary Firmware文件 ------------------------ $ cd ~/FSLMQXOS_4_1_2_Vybrid/mqx/examples/hello/build/make/hello_twrvf65gs10_m4/gcc_arm/ram_release $ export PATH=~/gcc-arm-none-eabi-4_9-2014q1/bin/:$PATH $ arm-none-eabi-objcopy -O binary hello_twrvf65gs10_m4.elf hello_twrvf65gs10_m4.bin ------------------------ d). 查看应用入口地址 由于二进制程序没有可以指明加载地址或入口地址的头部信息,因此需要在加载的时候手动添加 ------------------------ $ arm-none-eabi-objdump -f hello_twrvf65gs10_m4.elf   hello_twrvf65gs10_m4.elf:     file format elf32-littlearm architecture: arm, flags 0x00000112: EXEC_P, HAS_SYMS, D_PAGED start address 0x3f0007b1 ------------------------ e). 运行MQX 将bin文件复制到Colibri VF61 A5核心的Linux系统上面,运行下面命令启动mcc然后下载并运行MQX在M4核心 ------------------------ # modprobe mcc # mqxboot hello_twrvf65gs10_m4.bin 0x3f000000 0x3f0007b1 ------------------------ f). 查看M4串口输出 将Colibri开发板UARTB接口连接到开发主机 ------------------------ $ sudo minicom -D /dev/ttyUSB1 -d 115200 Welcome to minicom 2.7   OPTIONS: I18n Compiled on Jan  1 2014, 17:13:19. Port /dev/ttyUSB1, 14:58:22 Press CTRL-A Z for help on special keys   Hello World ------------------------ 5). GPIO demo 在M4运行MQX GPIO demo, 通过BSP_BUTTON1来控制打开和关闭BSP_LED1 a). 查看M4对应管脚定义 确定BSP_BUTTON1对应GPIO管脚为PTB16,BSP_LED1对应GPIO管脚为PTB0 ------------------------ $ vi FSLMQXOS_4_1_2_Vybrid/mqx/source/bsp/twrvf65gs10_m4/twrvf65gs10_m4.h   ... #define BSP_LED1                            (LWGPIO_PIN_PTB0) ... #define BSP_SW1                             (LWGPIO_PIN_PTB16) ... #define BSP_BUTTON1                         BSP_SW1 ... ------------------------ b). 确认M4 GPIO管脚资源 通过查询Colibri VF61手册和A5 Linux Device Tree文件, 发现PTB0被A5 Linux pwm0占用,而PTB16虽然被flexcan1占用但默认并为启用,因此首先需要根据这里的说明先重新编译A5 Linux Device Tree文件将pwm0 disable以免管脚资源冲突;然后在Colibri载板上面将PTB0 (SODIMM 59)连接到X21 LED1 (Pin 2), PTB16 (SODIMM 63)连接到X21 SW6 (Pin 11)
c). 同样方法编译MQX GPIO Firmware ------------------------ $ cd ~/FSLMQXOS_4_1_2_Vybrid/mqx/examples/gpio/build/make/gpio_twrvf65gs10_m4 $ ./build_gcc_arm.sh $ cd gcc_arm/ram_release/ $ export PATH=~/gcc-arm-none-eabi-4_9-2014q1/bin/:$PATH $ arm-none-eabi-objcopy -O binary gpio_twrvf65gs10_m4.elf gpio_twrvf65gs10_m4.bin $ arm-none-eabi-objdump -f gpio_twrvf65gs10_m4.elf   gpio_twrvf65gs10_m4.elf:     file format elf32-littlearm architecture: arm, flags 0x00000112: EXEC_P, HAS_SYMS, D_PAGED start address 0x3f000e51 ------------------------ d). 部署并测试demo ./ 在VF61 A5 Linux上面部署并运行MQX GPIO到M4 ------------------------ # mqxboot gpio_twrvf65gs10_m4.bin 0x3f000000 0x3f000e51 ------------------------ ./ 在M4 串口输出打印按键3次 ------------------------ ====================== GPIO Example ====================== The (SW1) button is configured to trigger GPIO interrupt. Press the (SW1) button 3x to continue. ------------------------ ./ 按Colibri 开发板SW6 3次后,即可通过SW6控制LED1 ------------------------ Button pressed 3x   The (SW1) button state is now polled. Press the (SW1) button to switch LED on or off   Button pressed ------------------------ 6). MCC Pingpong demo 下面通过MCC Pinpong demo来测试A5和M4之间的信息传递 a). 配置MCC版本 MQX 4.1.2版本默认采用MCC V2版本,但也同时提供了V1版本源代码;由于目前VF61 Linux只支持MCC V1版本,因此首先要用V1版本源代码替换V2版本 ------------------------ $ cd ~/FSLMQXOS_4_1_2_Vybrid/mcc/source $ unzip mcc_version_1_2.zip -d ../.  //按提示选择全部替换 $ vi mcc_vf600.c //如下面红 {MOD}部分修改 static const unsigned int mcc_cpu_to_cpu_vectors[] = { GIC_CPU_to_CPU_int0, NVIC_CPU_to_CPU_int0 }; ------------------------ b). 编译MCC ------------------------ $ cd ~/FSLMQXOS_4_1_2_Vybrid/mcc//build/make/mcc_twrvf65gs10_m4 $ ./build_gcc_arm.sh ------------------------ c). 编译Pingpong demo ------------------------ $ cd ~/FSLMQXOS_4_1_2_Vybrid/mcc/examples/pingpong/build/make/pingpong_example_twrvf65gs10_m4 $ ./build_gcc_arm.sh ------------------------ d). 部署运行测试Pingpong demo 和之前同样方法获得bin和入口地址,并通过A5 Linux运行到M4上面 ./ A5 Linux部署执行Pingpong demo ------------------------ $ mqxboot pingpong_example_twrvf65gs10_m4.bin 0x3f000000 0x3f001095 ------------------------ ./ 运行后, M4串口输出 ------------------------ Responder task started, MCC version is 001.002   ------------------------ ./ 然后在A5 Linux运行自带的Pingpong应用 ------------------------ mcc-pingpong ------------------------ ./ 然后M4串口输出 ------------------------ Responder task received a msg                                                   Message: Size=4, DATA = 1                                                       Responder task received a msg                                                    Message: Size=4, DATA = 3 ... ------------------------ ./ 同样A5串口输出 ------------------------ version: 001.002                                                                Message: Size=4, DATA = 2 after 0.004325 seconds.                                Message: Size=4, DATA = 4 after 0.004340 seconds.                               Message: Size=4, DATA = 6 after 0.004669 seconds. ... ------------------------ 7). 总结 本文简单展示了在VF61 M4核心上面运行MQX以及A5和M4核心通信例程,可见MQX可以非常方便的部署在NXP处理器上面,详细的MQX应用开发可以参考下面文档. FSLMQXOS_4_1_2_Vybrid/doc http://developer.toradex.com/knowledge-base/mqx-on-the-cortex-m4-of-a-colibri-vf61