mbed CLI-离线开发工具

Mbed OS是ARM公司自己打造、主打IoT的解决方案,是一个针对ARM CortexM系列处理器的嵌入式开源生态。mbedOS现在还处于成长和推广阶段,在国内真正应用的客户还很少。

Mbed OS主推在线编译,但许多人习惯用离线开发嵌入式软件,Mbed OS提供了Mbed CLI,基于命令行的开发包,它是用python开发的。

Mbed CLI的工作流程

1. 为一个应用程序,程序库,或者导入的模块,建立一个新的repository(代码空间),这一步同时导入了Mbed OS代码库(Mbed OS codebase)

2. 建立你的程序

3. 测试

4. 发布你的应用程序

搭建环境

开发板:NUCLEO-F207ZG

开发工具:

mbedOS支持三种开发工具:

1. 在线IDE

2. Mbed CLI控制台

3. 第三方开发工具,如IAR,MDK

在线IDE编译很方便快捷,但没有调试功能。第三方的IDE对于我们来说也不是重点。我们着重会来介绍Mbed-CLI,它可以代码仓库版本控制、依赖管理、代码发布、从其他地方获取代码、调用编译系统及其他。

Mbed CLI 安装

Windows安装比较简单,直接到官网(https://os.mbed.com/blog/entry/windows-installer-for-mbed-cli/)下载安装,下载链接https://mbed-media.mbed.com/filer_public/7f/46/7f46e205-52f5-48e2-be64-8f30d52f6d75/mbed_installer_v041.exe

LINUX安装,需要先安装以下工具

  • Python – mbed CLI 是用Python写的,并且在 version 2.7.11 上做过完整测试,不兼容x.
  • Git– version 1.9.5 or later
  • Mercurial– version 2.2.2 or later
  • GNU ARM– ARM GCC交叉编译工具

$ git clone https://github.com/ARMmbed/mbed-cli

$ python setup.py install

参考链接https://docs.mbed.com/docs/mbed-os-handbook/en/5.1/dev_tools/cli/

Mbed CLI运行

Windows进入命令行,输入mbed运行。

显示Mbed CLI的常见参数。

配置下GCC的路径(你安装GNU ARM的路径):

mbed config –global GCC_ARM_PATH “C:\Program Files (x86)\ GNU Tools ARM Embedded\6 2017-q2-update\bin”

mbed config –list检查

快速例子:

mbed import mbed-os-example-blinky

cd mbed-os-example-blinky

mbed compile –S 检查一下支持列表

针对NUCLEO_F207ZG开发板进行编译

mbed compile -t GCC_ARM -m NUCLEO_F207ZG

Building project mbed-os-example-blinky (NUCLEO_F207ZG, GCC_ARM)

Scan: .

Scan: env

Scan: mbed

Scan: FEATURE_LWIP

Compile [  0.3%]: AnalogIn.cpp

Compile [  0.5%]: BusIn.cpp

Compile [  0.8%]: main.cpp

Compile [  1.1%]: BusInOut.cpp

Compile [  1.3%]: BusOut.cpp

Compile [  1.6%]: CAN.cpp

Compile [  1.9%]: FlashIAP.cpp

Compile [  2.1%]: Ethernet.cpp

Compile [  2.4%]: I2CSlave.cpp

Compile [  2.7%]: InterruptIn.cpp

Compile [  2.9%]: I2C.cpp

Compile [  3.2%]: InterruptManager.cpp

Compile [  3.5%]: RawSerial.cpp

Compile [  3.7%]: SPISlave.cpp

Compile [  4.0%]: SPI.cpp

Compile [  4.3%]: Serial.cpp

Compile [  4.5%]: Ticker.cpp

Compile [  4.8%]: SerialBase.cpp

Compile [  5.1%]: Timeout.cpp

Compile [  5.3%]: Timer.cpp

Compile [  5.6%]: TimerEvent.cpp

Compile [  5.9%]: UARTSerial.cpp

Compile [  6.1%]: EventQueue.cpp

Compile [  6.4%]: equeue.c

Compile [  6.6%]: equeue_posix.c

Compile [  6.9%]: equeue_mbed.cpp

Compile [  7.2%]: emac_lwip.c

Compile [  7.4%]: mbed_shared_queues.cpp

Compile [  7.7%]: emac_stack_lwip.cpp

Compile [  8.0%]: stm32f2_eth_init.c

Compile [  8.2%]: stm32f2_eth_conf.c

Compile [  8.5%]: EthernetInterface.cpp

Compile [  8.8%]: lwip_checksum.c

Compile [  9.0%]: lwip_memcpy.c

Compile [  9.3%]: stm32xx_emac.c

Compile [  9.6%]: lwip_random.c

Compile [  9.8%]: lwip_sys_arch.c

Compile [ 10.1%]: lwip_tcp_isn.c

…… ……

Compile [ 99.5%]: stm_spi_api.c

Compile [ 99.7%]: us_ticker_32b.c

Compile [100.0%]: test_env.cpp

Link: mbed-os-example-blinky

Elf2Bin: mbed-os-example-blinky

+—————————————————————————————————————+——-+——-+——-+

| Module                                                                                                        | .text | .data |  .bss |

+—————————————————————————————————————+——-+——-+——-+

| [fill]                                                                                                        |    63 |     4 |    19 |

| [lib]/c.a                                                                                                     | 17115 |  2472 |    89 |

| [lib]/gcc.a                                                                                                   |  3868 |     0 |     0 |

| [lib]/misc                                                                                                    |   252 |    16 |    28 |

| main.o                                                                                                        |    72 |     4 |    28 |

| mbed-os\drivers\I2C.o                                                                                         |    16 |     0 |     0 |

| mbed-os\drivers\SPI.o                                                                                         |   120 |     4 |   100 |

| mbed-os\features\FEATURE_LWIP\lwip-interface\lwip-eth\arch\TARGET_STM\stm32xx_emac.o                          |    24 |     0 | 12556 |

| mbed-os\features\FEATURE_LWIP\lwip-interface\lwip-sys\arch\lwip_sys_arch.o                                    |    20 |     0 |     0 |

| mbed-os\hal\mbed_gpio.o                                                                                       |    78 |     0 |     0 |

| mbed-os\hal\mbed_pinmap_common.o                                                                              |   218 |     0 |     0 |

| mbed-os\hal\mbed_sleep_manager.o                                                                              |   219 |     0 |     2 |

| mbed-os\hal\mbed_ticker_api.o                                                                                 |   296 |     0 |     0 |

| mbed-os\hal\mbed_us_ticker_api.o                                                                              |    52 |     0 |    24 |

| mbed-os\platform\mbed_alloc_wrappers.o                                                                        |    16 |     0 |     0 |

| mbed-os\platform\mbed_assert.o                                                                                |    85 |     0 |     0 |

| mbed-os\platform\mbed_board.o                                                                                 |   196 |     0 |     0 |

| mbed-os\platform\mbed_critical.o                                                                              |   305 |     0 |     5 |

| mbed-os\platform\mbed_error.o                                                                                 |    44 |     0 |     1 |

| mbed-os\platform\mbed_retarget.o                                                                              |   498 |     4 |   264 |

| mbed-os\platform\mbed_wait_api_rtos.o                                                                         |    98 |     0 |     0 |

| mbed-os\rtos\TARGET_CORTEX\mbed_boot.o                                                                        |   467 |     0 |  4360 |

| mbed-os\rtos\TARGET_CORTEX\mbed_rtx_handlers.o                                                                |   663 |     0 |     0 |

| mbed-os\rtos\TARGET_CORTEX\mbed_rtx_idle.o                                                                    |    42 |     4 |     0 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\TARGET_M3\TOOLCHAIN_GCC\irq_cm3.o                                             |   144 |     0 |     0 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rt_OsEventObserver.o                                                          |     0 |     0 |     4 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rtx_delay.o                                                                   |    72 |     0 |     0 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rtx_evr.o                                                                     |   116 |     0 |     0 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rtx_kernel.o                                                                  |   883 |   176 |     0 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rtx_lib.o                                                                     |   260 |     0 |  1620 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rtx_memory.o                                                                  |   242 |     0 |     0 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rtx_mempool.o                                                                 |   288 |     0 |     0 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rtx_msgqueue.o                                                                |  1700 |     0 |     0 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rtx_mutex.o                                                                   |   824 |     0 |     0 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rtx_semaphore.o                                                               |   262 |     0 |     0 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rtx_system.o                                                                  |   462 |     0 |     0 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rtx_thread.o                                                                  |  2036 |     0 |     0 |

| mbed-os\rtos\TARGET_CORTEX\rtx5\rtx_timer.o                                                                   |   216 |     0 |     0 |

| mbed-os\rtos\Thread.o                                                                                         |    20 |     0 |     4 |

| mbed-os\targets\TARGET_STM\TARGET_STM32F2\TARGET_NUCLEO_F207ZG\PeripheralPins.o                               |   204 |     0 |     0 |

| mbed-os\targets\TARGET_STM\TARGET_STM32F2\TARGET_NUCLEO_F207ZG\device\TOOLCHAIN_GCC_ARM\startup_stm32f207xx.o |   442 |     0 |     0 |

| mbed-os\targets\TARGET_STM\TARGET_STM32F2\TARGET_NUCLEO_F207ZG\device\system_clock.o                          |   316 |     0 |     0 |

| mbed-os\targets\TARGET_STM\TARGET_STM32F2\device\stm32f2xx_hal.o                                              |    82 |     0 |     4 |

| mbed-os\targets\TARGET_STM\TARGET_STM32F2\device\stm32f2xx_hal_cortex.o                                       |    36 |     0 |     0 |

| mbed-os\targets\TARGET_STM\TARGET_STM32F2\device\stm32f2xx_hal_eth.o                                          |   116 |     0 |     0 |

| mbed-os\targets\TARGET_STM\TARGET_STM32F2\device\stm32f2xx_hal_pwr.o                                          |    88 |     0 |     0 |

| mbed-os\targets\TARGET_STM\TARGET_STM32F2\device\stm32f2xx_hal_rcc.o                                          |  1332 |     0 |     0 |

| mbed-os\targets\TARGET_STM\TARGET_STM32F2\device\stm32f2xx_hal_tim.o                                          |   342 |     0 |     0 |

| mbed-os\targets\TARGET_STM\TARGET_STM32F2\device\stm32f2xx_hal_uart.o                                         |   658 |     0 |     0 |

| mbed-os\targets\TARGET_STM\TARGET_STM32F2\device\system_stm32f2xx.o                                           |   140 |     4 |     0 |

| mbed-os\targets\TARGET_STM\TARGET_STM32F2\serial_device.o                                                     |   670 |     0 |   592 |

| mbed-os\targets\TARGET_STM\can_api.o                                                                          |   284 |     0 |    12 |

| mbed-os\targets\TARGET_STM\gpio_api.o                                                                         |   606 |     0 |     0 |

| mbed-os\targets\TARGET_STM\hal_tick_32b.o                                                                     |   328 |     0 |     4 |

| mbed-os\targets\TARGET_STM\mbed_overrides.o                                                                   |    22 |     0 |     0 |

| mbed-os\targets\TARGET_STM\pinmap.o                                                                           |   610 |     0 |     0 |

| mbed-os\targets\TARGET_STM\serial_api.o                                                                       |   188 |     0 |     0 |

| mbed-os\targets\TARGET_STM\sleep.o                                                                            |    78 |     0 |     0 |

| mbed-os\targets\TARGET_STM\us_ticker_32b.o                                                                    |    98 |     0 |    64 |

| Subtotals                                                                                                     | 38992 |  2688 | 19780 |

+—————————————————————————————————————+——-+——-+——-+

Total Static RAM memory (data + bss): 22468 bytes

Total Flash memory (text + data): 41680 bytes

 

Image: .\BUILD\NUCLEO_F207ZG\GCC_ARM\mbed-os-example-blinky.bin

 

最后

联机烧录。