Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BUILDING.md 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. # Mbed SDK build script environment
  2. ## Introduction
  3. Mbed test framework allows users to test their mbed devices’ applications, build mbed SDK library, re-run tests, run mbed SDK regression, add new tests and get all this results automatically. Everything is done on your machine so you have a full control over compilation, and tests you run.
  4. It's is using Python 2.7 programming language to drive all tests so make sure Python 2.7 is installed on your system and included in your system PATH. To compile mbed SDK and tests you will need one or more supported compilers installed on your system.
  5. To follow this short introduction you should already:
  6. * Know what mbed SDK is in general.
  7. * Know how to install Python 2.7, ARM target cross compilers.
  8. * You have C/C++ programming experience and at least willingness to learn a bit about Python.
  9. ## Test automation
  10. Currently our simple test framework allows users to run tests on their machines (hosts) in a fully automated manner. All you need to do is to prepare two configuration files.
  11. ## Test automation limitations
  12. Note that for tests which require connected external peripherals, for example Ethernet, SD flash cards, external EEPROM tests, loops etc. you need to:
  13. * Modify test source code to match components' pin names to actual mbed board pins where peripheral is connected or
  14. * Wire your board the same way test defines it.
  15. ## Prerequisites
  16. mbed test suite and build scripts are Python 2.7 applications and require Python 2.7 runtime environment and [setuptools](https://pythonhosted.org/an_example_pypi_project/setuptools.html) to install dependencies.
  17. What we need:
  18. * Installed [Python 2.7](https://www.python.org/download/releases/2.7) programming language.
  19. * Installed [setuptools](https://pythonhosted.org/an_example_pypi_project/setuptools.html#installing-setuptools-and-easy-install)
  20. * Optionally you can install [pip](https://pip.pypa.io/en/latest/installing.html) which is the PyPA recommended tool for installing Python packages from command line.
  21. mbed SDK in its repo root directory specifies ```setup.py``` file which holds information about all packages which are dependencies for it. Bear in mind only few simple steps are required to install all dependencies.
  22. First, clone mbed SDK repo and go to mbed SDk repo's directory:
  23. ```
  24. $ git clone https://github.com/mbedmicro/mbed.git
  25. $ cd mbed
  26. ```
  27. Second, invoke ```setup.py``` so ```setuptools``` can install mbed SDK's dependencies (external Python modules required by mbed SDK):
  28. ```
  29. $ python setup.py install
  30. ```
  31. or
  32. ```
  33. $ sudo python setup.py install
  34. ```
  35. when your system requires administrator rights to install new Python packages.
  36. ## Prerequisites (manual Python package dependency installation)
  37. **Please only read this chapter if you had problems installing mbed SDK dependencies to Python packages**.
  38. Below you can find the list of mbed SDK dependencies to Python modules with instructions how to install them manually.
  39. You can skip this part if you've already install [Python 2.7](https://www.python.org/download/releases/2.7) and [setuptools](https://pythonhosted.org/an_example_pypi_project/setuptools.html) and successfully [installed all dependencies](#prerequisites).
  40. * Please make sure you've installed [pip](https://pip.pypa.io/en/latest/installing.html) or [easy_install](https://pythonhosted.org/setuptools/easy_install.html#installing-easy-install)
  41. Note: Easy Install is a python module (easy_install) bundled with [setuptools](https://pythonhosted.org/an_example_pypi_project/setuptools.html#installing-setuptools-and-easy-install) that lets you automatically download, build, install, and manage Python packages.
  42. * Installed [pySerial](https://pypi.python.org/pypi/pyserial) module for Python 2.7.
  43. pySerial can be installed from PyPI, either manually downloading the files and installing as described below or using:
  44. ```
  45. $ pip install pyserial
  46. ```
  47. or:
  48. ```
  49. easy_install -U pyserial
  50. ```
  51. * Installed [prettytable](https://code.google.com/p/prettytable/wiki/Installation) module for Python 2.7.
  52. prettytable can be installed from PyPI, either manually downloading the files and installing as described below or using:
  53. ```
  54. $ pip install prettytable
  55. ```
  56. * Installed [IntelHex](https://pypi.python.org/pypi/IntelHex) module.
  57. IntelHex may be downloaded from https://launchpad.net/intelhex/+download or http://www.bialix.com/intelhex/.
  58. Assuming Python is properly installed on your platform, installation should just require running the following command from the root directory of the archive:
  59. ```
  60. sudo python setup.py install
  61. ```
  62. This will install the intelhex package into your system’s site-packages directory. After that is done, any other Python scripts or modules should be able to import the package using:
  63. ```
  64. $ python
  65. Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
  66. Type "help", "copyright", "credits" or "license" for more information.
  67. >>> from intelhex import IntelHex
  68. >>>
  69. ```
  70. * You can check if you have correctly installed the above modules (or you already have them) by starting Python and importing both modules.
  71. ```
  72. $ python
  73. Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
  74. Type "help", "copyright", "credits" or "license" for more information.
  75. >>> import serial
  76. >>> import prettytable
  77. >>> from intelhex import IntelHex
  78. >>>
  79. ```
  80. * Installed Git open source distributed version control system.
  81. * Installed at least one of the supported by Mbed SDK workspace tools compilers:
  82. Compiler | Mbed SDK Abbreviation | Example Version
  83. -----------------------|-----------------------|-----------
  84. Keil ARM Compiler | ARM, uARM | ARM C/C++ Compiler, 5.03 [Build 117]
  85. GCC ARM | GCC_ARM | gcc version 4.8.3 20131129 (release)
  86. GCC CodeSourcery | GCC_CS | gcc version 4.8.1 (Sourcery CodeBench Lite 2013.11-24)
  87. GCC CodeRed | GCC_CR | gcc version 4.6.2 20121016 (release)
  88. IAR Embedded Workbench | IAR | IAR ANSI C/C++ Compiler V6.70.1.5641/W32 for ARM
  89. * Mbed board. You can find list of supported platforms [here](https://mbed.org/platforms/).
  90. ### Getting Mbed SDK sources with test suite
  91. So you have already installed Python (with required modules) together with at least one supported compiler you will use with your mbed board. Great!
  92. Now let's go further and try to get Mbed SDK with test suite together. So let's clone latest Mbed SDK source code and configure path to our compiler(s) in next few steps.
  93. * Open console and run command below to clone Mbed SDK repository hosted on [Github](https://github.com/mbedmicro/mbed).
  94. ```
  95. $ git clone https://github.com/mbedmicro/mbed.git
  96. Cloning into 'mbed'...
  97. remote: Counting objects: 37221, done.
  98. remote: Compressing objects: 100% (3/3), done.
  99. remote: Total 37221 (delta 0), reused 0 (delta 0), pack-reused 37218
  100. Receiving objects: 100% (37221/37221), 20.38 MiB | 511.00 KiB/s, done.
  101. Resolving deltas: 100% (24455/24455), done.
  102. Checking connectivity... done.
  103. Checking out files: 100% (3994/3994), done.
  104. ```
  105. * Now you can go to mbed directory you've just cloned and you can see root directory structure of our Mbed SDK library sources. Just type following commands:
  106. ```
  107. $ cd mbed
  108. $ ls
  109. LICENSE MANIFEST.in README.md libraries setup.py travis workspace_tools
  110. ```
  111. Directory structure we are interested in:
  112. ```
  113. mbed/workspace_tools/ - test suite scripts, build scripts etc.
  114. mbed/library/tests/ - mbed SDK tests,
  115. mbed/library/tests/mbed/ - tests for mbed SDK and peripherals tests,
  116. mbed/library/tests/net/echo/ - tests for Ethernet interface,
  117. mbed/library/tests/rtos/mbed/ - tests for RTOS.
  118. ```
  119. ### Workspace tools
  120. Workspace tools are set of Python scripts used off-line by Mbed SDK team to:
  121. * Compile and build mbed SDK,
  122. * Compile and build libraries included in mbed SDK repo like e.g. ETH (Ethernet), USB, RTOS or CMSIS,
  123. * Compile, build and run mbed SDK tests,
  124. * Run test regression locally and in CI server,
  125. * Get library, target, test configuration (paths, parameters, names etc.).
  126. ### Configure workspace tools to work with your compilers
  127. Before we can run our first test we need to configure our test environment a little!
  128. Now we need to tell workspace tools where our compilers are.
  129. * Please to go ```mbed/workspace_tools/``` directory and create empty file called ```private_settings.py```.
  130. ```
  131. $ touch private_settings.py
  132. ```
  133. * Populate this file the Python code below:
  134. ```python
  135. from os.path import join
  136. # ARMCC
  137. ARM_PATH = "C:/Work/toolchains/ARMCompiler_5.03_117_Windows"
  138. ARM_BIN = join(ARM_PATH, "bin")
  139. ARM_INC = join(ARM_PATH, "include")
  140. ARM_LIB = join(ARM_PATH, "lib")
  141. ARM_CPPLIB = join(ARM_LIB, "cpplib")
  142. MY_ARM_CLIB = join(ARM_PATH, "lib", "microlib")
  143. # GCC ARM
  144. GCC_ARM_PATH = "C:/Work/toolchains/gcc_arm_4_8/4_8_2013q4/bin"
  145. # GCC CodeSourcery
  146. GCC_CS_PATH = "C:/Work/toolchains/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
  147. # GCC CodeRed
  148. GCC_CR_PATH = "C:/Work/toolchains/LPCXpresso_6.1.4_194/lpcxpresso/tools/bin"
  149. # IAR
  150. IAR_PATH = "C:/Work/toolchains/iar_6_5/arm"
  151. SERVER_ADDRESS = "127.0.0.1"
  152. LOCALHOST = "127.0.0.1"
  153. # This is moved to separate JSON configuration file used by singletest.py
  154. MUTs = {
  155. }
  156. ```
  157. Note: You need to provide the absolute path to your compiler(s) installed on your host machine. Replace corresponding variable values with paths to compilers installed in your system:
  158. * ```ARM_PATH``` for armcc compiler.
  159. * ```GCC_ARM_PATH``` for GCC ARM compiler.
  160. * ```GCC_CS_PATH``` for GCC CodeSourcery compiler.
  161. * ```GCC_CR_PATH``` for GCC CodeRed compiler.
  162. * ```IAR_PATH``` for IAR compiler.
  163. If for example you do not use ```IAR``` compiler you do not have to modify anything. Workspace tools will use ```IAR_PATH`` variable only if you explicit ask for it from command line. So do not worry and replace only paths for your installed compilers.
  164. Note: Because this is a Python script and ```ARM_PATH```, ```GCC_ARM_PATH```, ```GCC_CS_PATH```, ```GCC_CR_PATH```, ```IAR_PATH``` are Python string variables please use double backlash or single slash as path's directories delimiter to avoid incorrect path format. For example:
  165. ```python
  166. ARM_PATH = "C:/Work/toolchains/ARMCompiler_5.03_117_Windows"
  167. GCC_ARM_PATH = "C:/Work/toolchains/gcc_arm_4_8/4_8_2013q4/bin"
  168. GCC_CS_PATH = "C:/Work/toolchains/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
  169. GCC_CR_PATH = "C:/Work/toolchains/LPCXpresso_6.1.4_194/lpcxpresso/tools/bin"
  170. IAR_PATH = "C:/Work/toolchains/iar_6_5/arm"
  171. ```
  172. Note: Settings in ```private_settings.py``` will overwrite variables with default values in ```mbed/workspace_tools/settings.py``` file.
  173. ## Build Mbed SDK library from sources
  174. Let's build mbed SDK library off-line from sources using your compiler. We've already cloned mbed SDK sources, we've also installed compilers and added their paths to ```private_settings.py```.
  175. We now should be ready to use workspace tools script ```build.py``` to compile and build mbed SDK from sources.
  176. We are still using console. You should be already in ```mbed/workspace_tools/``` directory if not go to ```mbed/workspace_tools/``` and type below command:
  177. ```
  178. $ python build.py -m LPC1768 -t ARM
  179. ```
  180. or if you want to take advantage from multi-threaded compilation please use option ```-j X``` where ```X``` is number of cores you want to use to compile mbed SDK. See below:
  181. ```
  182. $ python build.py -m LPC1768 -t ARM -j 4
  183. Building library CMSIS (LPC1768, ARM)
  184. Copy: core_ca9.h
  185. Copy: core_caFunc.h
  186. ...
  187. Compile: us_ticker_api.c
  188. Compile: wait_api.c
  189. Library: mbed.ar
  190. Creating archive 'C:\temp\x\mbed\build\mbed\TARGET_LPC1768\TOOLCHAIN_ARM_STD\mbed.ar'
  191. Copy: board.o
  192. Copy: retarget.o
  193. Completed in: (42.58)s
  194. Build successes:
  195. * ARM::LPC1768
  196. ```
  197. Above command will build mbed SDK for [LPC1768](http://developer.mbed.org/platforms/mbed-LPC1768/) platform using ARM compiler.
  198. Let's have a look at directory structure under ```mbed/build/```. We can see for ```LPC1768``` new directory ```TARGET_LPC1768``` was created. This directory contains all build primitives.
  199. Directory ```mbed/TARGET_LPC1768/TOOLCHAIN_ARM_STD/``` conteins mbed SDK library ```mbed.ar```. This directory structure also stores all needed headers which you should use with ```mbed.ar``` when building your own software.
  200. ```
  201. $ tree ./mbed/build/
  202. Folder PATH listing
  203. Volume serial number is 006C006F 6243:3EA9
  204. ./MBED/BUILD
  205. +---mbed
  206. +---.temp
  207. ¦ +---TARGET_LPC1768
  208. ¦ +---TOOLCHAIN_ARM_STD
  209. ¦ +---TARGET_NXP
  210. ¦ +---TARGET_LPC176X
  211. ¦ +---TOOLCHAIN_ARM_STD
  212. +---TARGET_LPC1768
  213. +---TARGET_NXP
  214. ¦ +---TARGET_LPC176X
  215. ¦ +---TARGET_MBED_LPC1768
  216. +---TOOLCHAIN_ARM_STD
  217. ```
  218. Note: Why ```LCP1768```? For this example we are using ```LPC1768``` because this platform supports all compilers so you are sure you only need to specify proper compiler.
  219. If you are not using ARM Compiler replace ```ARM``` with your compiler nickname: ```GCC_ARM```, ```GCC_CS```, ```GCC_CR``` or ```IAR```. For example if you are using IAR type command:
  220. ```
  221. $ python build.py -m LPC1768 -t IAR
  222. ```
  223. Note: Workspace tools track changes in source code. So if for example mbed SDK or test source code changes ```build.py``` script will recompile project with all dependencies. If there are no changes in code consecutive mbed SDK re-builds using build.py will not rebuild project if this is not necessary. Try to run last command once again, we can see script ```build.py``` will not recompile project (there are no changes):
  224. ```
  225. $ python build.py -m LPC1768 -t ARM
  226. Building library CMSIS (LPC1768, ARM)
  227. Building library MBED (LPC1768, ARM)
  228. Completed in: (0.15)s
  229. Build successes:
  230. * ARM::LPC1768
  231. ```
  232. ### build.py script
  233. Build script located in mbed/workspace_tools/ is our core script solution to drive compilation, linking and building process for:
  234. * mbed SDK (with libs like Ethernet, RTOS, USB, USB host).
  235. * Tests which also can be linked with libraries like RTOS or Ethernet.
  236. Note: Test suite also uses the same build script, inheriting the same properties like auto dependency tracking and project rebuild in case of source code changes.
  237. Build.py script is a powerful tool to build mbed SDK for all available platforms using all supported by mbed cross-compilers. Script is using our workspace tools build API to create desired platform-compiler builds. Use script option ```--h``` (help) to check all script parameters.
  238. ```
  239. $ python build.py --help
  240. ```
  241. * The command line parameter ```-m``` specifies the MCUs/platforms for which you want to build the mbed SDK. More than one MCU(s)/platform(s) may be specified with this parameter using comma as delimiter.
  242. Example for one platform build:
  243. ```
  244. $ python build.py -m LPC1768 -t ARM
  245. ```
  246. or for many platforms:
  247. ```
  248. $ python build.py -m LPC1768,NUCLEO_L152RE -t ARM
  249. ```
  250. * Parameter ```-t``` defined which toolchain should be used for mbed SDK build. You can build Mbed SDK for multiple toolchains using one command.
  251. Below example (note there is no space after commas) will compile mbed SDK for Freescale Freedom KL25Z platform using ARM and GCC_ARM compilers:
  252. ```
  253. $ python build.py -m KL25Z -t ARM,GCC_ARM
  254. ```
  255. * You can combine this technique to compile multiple targets with multiple compilers.
  256. Below example will compile mbed SDK for Freescale's KL25Z and KL46Z platforms using ARM and GCC_ARM compilers:
  257. ```
  258. $ python build.py -m KL25Z,KL46Z -t ARM,GCC_ARM
  259. ```
  260. * Building libraries included in mbed SDK's source code. Parameters ```-r```, ```-e```, ```-u```, ```-U```, ```-d```, ```-b``` will add ```RTOS```, ```Ethernet```, ```USB```, ```USB Host```, ```DSP```, ```U-Blox``` libraries respectively.
  261. Below example will build Mbed SDK library for for NXP LPC1768 platform together with RTOS (```-r``` switch) and Ethernet (```-e``` switch) libraries.
  262. ```
  263. $ python build.py -m LPC1768 -t ARM -r -e
  264. Building library CMSIS (LPC1768, ARM)
  265. Building library MBED (LPC1768, ARM)
  266. Building library RTX (LPC1768, ARM)
  267. Building library RTOS (LPC1768, ARM)
  268. Building library ETH (LPC1768, ARM)
  269. Completed in: (0.48)s
  270. Build successes:
  271. * ARM::LPC1768
  272. ```
  273. * If you’re unsure which platforms and toolchains are supported please use switch ```-S``` to print simple matrix of platform to compiler dependencies.
  274. ```
  275. $ python python build.py -S
  276. +-------------------------+-----------+-----------+-----------+-----------+-----------+-----------+------------+---------------+
  277. | Platform | ARM | uARM | GCC_ARM | IAR | GCC_CR | GCC_CS | GCC_CW_EWL | GCC_CW_NEWLIB |
  278. +-------------------------+-----------+-----------+-----------+-----------+-----------+-----------+------------+---------------+
  279. | APPNEARME_MICRONFCBOARD | Supported | Default | Supported | - | - | - | - | - |
  280. | ARCH_BLE | Default | - | Supported | Supported | - | - | - | - |
  281. | ARCH_GPRS | Supported | Default | Supported | Supported | Supported | - | - | - |
  282. ...
  283. | UBLOX_C029 | Supported | Default | Supported | Supported | - | - | - | - |
  284. | WALLBOT_BLE | Default | - | Supported | Supported | - | - | - | - |
  285. | XADOW_M0 | Supported | Default | Supported | Supported | Supported | - | - | - |
  286. +-------------------------+-----------+-----------+-----------+-----------+-----------+-----------+------------+---------------+
  287. *Default - default on-line compiler
  288. *Supported - supported off-line compiler
  289. Total platforms: 90
  290. Total permutations: 297
  291. ```
  292. Above list can be overwhelming so please do not hesitate to use switch ```-f``` to filter ```Platform``` column.
  293. ```
  294. $ python build.py -S -f ^K
  295. +--------------+-----------+---------+-----------+-----------+--------+--------+------------+---------------+
  296. | Platform | ARM | uARM | GCC_ARM | IAR | GCC_CR | GCC_CS | GCC_CW_EWL | GCC_CW_NEWLIB |
  297. +--------------+-----------+---------+-----------+-----------+--------+--------+------------+---------------+
  298. | K20D50M | Default | - | Supported | Supported | - | - | - | - |
  299. | K22F | Default | - | Supported | Supported | - | - | - | - |
  300. | K64F | Default | - | Supported | Supported | - | - | - | - |
  301. | KL05Z | Supported | Default | Supported | Supported | - | - | - | - |
  302. | KL25Z | Default | - | Supported | Supported | - | - | Supported | Supported |
  303. | KL43Z | Default | - | Supported | - | - | - | - | - |
  304. | KL46Z | Default | - | Supported | Supported | - | - | - | - |
  305. | NRF51_DK | Default | - | Supported | Supported | - | - | - | - |
  306. | NRF51_DK_OTA | Default | - | Supported | - | - | - | - | - |
  307. +--------------+-----------+---------+-----------+-----------+--------+--------+------------+---------------+
  308. *Default - default on-line compiler
  309. *Supported - supported off-line compiler
  310. Total platforms: 9
  311. Total permutations: 28
  312. ```
  313. or just give platform name:
  314. ```
  315. $ python build.py -S -f LPC1768
  316. +----------+---------+-----------+-----------+-----------+-----------+-----------+------------+---------------+
  317. | Platform | ARM | uARM | GCC_ARM | IAR | GCC_CR | GCC_CS | GCC_CW_EWL | GCC_CW_NEWLIB |
  318. +----------+---------+-----------+-----------+-----------+-----------+-----------+------------+---------------+
  319. | LPC1768 | Default | Supported | Supported | Supported | Supported | Supported | - | - |
  320. +----------+---------+-----------+-----------+-----------+-----------+-----------+------------+---------------+
  321. *Default - default on-line compiler
  322. *Supported - supported off-line compiler
  323. Total platforms: 1
  324. Total permutations: 6
  325. ```
  326. * You can be more verbose ```-v``` especially if you want to see each compilation / linking command build.py is executing:
  327. ```
  328. $ python build.py -t GCC_ARM -m LPC1768 -j 8 -v
  329. Building library CMSIS (LPC1768, GCC_ARM)
  330. Copy: LPC1768.ld
  331. Compile: startup_LPC17xx.s
  332. [DEBUG] Command: C:/Work/toolchains/gcc_arm_4_8/4_8_2013q4/bin\arm-none-eabi-gcc
  333. -x assembler-with-cpp -c -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
  334. -fmessage-length=0 -fno-exceptions -fno-builtin -ffunction-sections -fdata-sections -MMD
  335. -fno-delete-null-pointer-checks -fomit-frame-pointer -mcpu=cortex-m3 -mthumb -O2
  336. -DTARGET_LPC1768 -DTARGET_M3 -DTARGET_CORTEX_M -DTARGET_NXP -DTARGET_LPC176X
  337. -DTARGET_MBED_LPC1768 -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -D__CORTEX_M3 -DARM_MATH_CM3
  338. -DMBED_BUILD_TIMESTAMP=1424903604.77 -D__MBED__=1 -IC:\Work\mbed\libraries\mbed\targets\cmsis
  339. -IC:\Work\mbed\libraries\mbed\targets\cmsis\TARGET_NXP
  340. -IC:\Work\mbed\libraries\mbed\targets\cmsis\TARGET_NXP\TARGET_LPC176X -IC:\Work\mbed\libraries\mbed\targets\cmsis\TARGET_NXP\TARGET_LPC176X\TOOLCHAIN_GCC_ARM
  341. -o C:\Work\mbed\build\mbed\.temp\TARGET_LPC1768\TOOLCHAIN_GCC_ARM\TARGET_NXP\TARGET_LPC176X\TOOLCHAIN_GCC_ARM\startup_LPC17xx.o
  342. C:\Work\mbed\libraries\mbed\targets\cmsis\TARGET_NXP\TARGET_LPC176X\TOOLCHAIN_GCC_ARM\startup_LPC17xx.s
  343. [DEBUG] Return: 0
  344. ...
  345. ```
  346. ## CppUCheck analysis
  347. [Cppcheck](http://cppcheck.sourceforge.net/) is a static analysis tool for C/C++ code. Unlike C/C++ compilers and many other analysis tools it does not detect syntax errors in the code. Cppcheck primarily detects the types of bugs that the compilers normally do not detect. The goal is to detect only real errors in the code (i.e. have zero false positives).
  348. Prerequisites:
  349. * Please install ```CppCheck``` on your system before you want to use it with build scripts.
  350. * You should also add Cppcheck to your system path.
  351. ```build.py``` script supports switching between compilation and building and just static code analysis testing. You can use switch ```--cppcheck``` to perform CppCheck static code analysis.
  352. * When you are using --cppcheck switch all macros, toolchain dependencies etc. are preserved so you are sure you are checking exactly the same code you would compile for your application.
  353. * Cppcheck analysis can take up to few minutes on slower machines.
  354. * Usually you will use switches ```-t``` and ```-m``` to define toolchain and MCU (platform) respectively. You should do the same in case of CppCheck analysis. Please note that build script can also compile and build RTOS, Ethernet library etc. If you want to check those just use corresponding build script switches (e.g. ```-r```, ```-e```, ...).
  355. Example:
  356. ```
  357. $ python build.py -t uARM -m NUCLEO_F334R8 --cppcheck
  358. ```
  359. # make.py script
  360. ```make.pt``` is a ```mbed/workspace_tools/``` script used to build tests (we call them sometimes 'programs') one by one manually. Script allows you to flash board with test and execute it. This is deprecated functionality and will not be described here. Instead please use ```singletest.py``` file to build mbed SDK, tests and run automation for test cases included in ```mbedmicro/mbed```.
  361. Note: ```make.py``` script depends on existing already built mked SDK and library sources so you need to pre-build mbed SDK and for example RTOS library to link 'program' (test) with mebd SDK and RTOS library. To pre-build mbed SDK please use ```build.py``` script.
  362. Just for sake of example please see few ways to use ```make.py``` together with Freedom K64F board.
  363. * We need to build mbed SDK (in directory ```mbed/build/```:
  364. ```
  365. $ python build.py -t GCC_ARM -m K64F -j 8
  366. Building library CMSIS (K64F, GCC_ARM)
  367. Building library MBED (K64F, GCC_ARM)
  368. Completed in: (0.59)s
  369. Build successes:
  370. * GCC_ARM::K64F
  371. ```
  372. * We can print all 'programs' (test cases) ```make.py``` can build for us:
  373. ```
  374. $ python make.py
  375. .
  376. [ 0] MBED_A1: Basic
  377. [ 1] MBED_A2: Semihost file system
  378. [ 2] MBED_A3: C++ STL
  379. [ 3] MBED_A4: I2C TMP102
  380. .
  381. ```
  382. For example 'program' under index ```2``` is ```MBED_A3``` test case we can build and flash onto K64F board.
  383. * Building test with ```make.py``` by specifying test case name with ```-n``` option:
  384. ```
  385. $ python make.py -t GCC_ARM -m K64F -n MBED_A3
  386. Building project STL (K64F, GCC_ARM)
  387. Compile: main.cpp
  388. [Warning] main.cpp@76: In function 'int main()': deprecated conversion from string constant to 'char*' [-Wwrite-strings]
  389. .
  390. .
  391. .
  392. [Warning] main.cpp@76: In function 'int main()': deprecated conversion from string constant to 'char*' [-Wwrite-strings]
  393. Compile: test_env.cpp
  394. Link: stl
  395. Elf2Bin: stl
  396. Image: C:\Work\mbed\build\test\K64F\GCC_ARM\MBED_A3\stl.bin
  397. ```
  398. Because we previously have built mbed SDK we are now able to drive test case compilation and linking with mbed SDK and produce ```MBED_A3``` test case binary in build directory:
  399. ```
  400. C:\Work\mbed\build\test\K64F\GCC_ARM\MBED_A3\stl.bin
  401. ```
  402. For more help type ```$ python make.py --help``` in your command line.
  403. # project.py script
  404. ```project.py``` script is used to export test cases ('programs') from test case portfolio to off-line IDE. This is a easy way to export test project to IDEs such as:
  405. * codesourcery.
  406. * coide.
  407. * ds5_5.
  408. * emblocks.
  409. * gcc_arm.
  410. * iar.
  411. * kds.
  412. * lpcxpresso.
  413. * uvision.
  414. You can export project using command line. All you need to do is to specify mbed platform name (option ```-m```), your IDE (option ```-i```) and project name you want to export (option ```-n``` or (option ```-p```).
  415. In below example we export our project so we can work on it using GCC ARM cross-compiler. Building mechanism used to drive exported build will be ```Make```.
  416. ```
  417. $ python project.py -m K64F -n MBED_A3 -i gcc_arm
  418. Copy: test_env.h
  419. Copy: AnalogIn.h
  420. Copy: AnalogOut.h
  421. .
  422. .
  423. .
  424. Copy: K64FN1M0xxx12.ld
  425. Copy: main.cpp
  426. Successful exports:
  427. * K64F::gcc_arm C:\Work\mbed\build\export\MBED_A3_gcc_arm_K64F.zip
  428. ```
  429. You can see exporter placed compressed project export in ```zip``` file in ```mbed/build/export/``` directory.
  430. Example export file ```MBED_A3_gcc_arm_K64F.zip``` structure:
  431. ```
  432. MBED_A3
  433. ├───env
  434. └───mbed
  435. ├───api
  436. ├───common
  437. ├───hal
  438. └───targets
  439. ├───cmsis
  440. │ └───TARGET_Freescale
  441. │ └───TARGET_MCU_K64F
  442. │ └───TOOLCHAIN_GCC_ARM
  443. └───hal
  444. └───TARGET_Freescale
  445. └───TARGET_KPSDK_MCUS
  446. ├───TARGET_KPSDK_CODE
  447. │ ├───common
  448. │ │ └───phyksz8081
  449. │ ├───drivers
  450. │ │ ├───clock
  451. │ │ ├───enet
  452. │ │ │ └───src
  453. │ │ ├───interrupt
  454. │ │ └───pit
  455. │ │ ├───common
  456. │ │ └───src
  457. │ ├───hal
  458. │ │ ├───adc
  459. │ │ ├───can
  460. │ │ ├───dac
  461. │ │ ├───dmamux
  462. │ │ ├───dspi
  463. │ │ ├───edma
  464. │ │ ├───enet
  465. │ │ ├───flextimer
  466. │ │ ├───gpio
  467. │ │ ├───i2c
  468. │ │ ├───llwu
  469. │ │ ├───lptmr
  470. │ │ ├───lpuart
  471. │ │ ├───mcg
  472. │ │ ├───mpu
  473. │ │ ├───osc
  474. │ │ ├───pdb
  475. │ │ ├───pit
  476. │ │ ├───pmc
  477. │ │ ├───port
  478. │ │ ├───rcm
  479. │ │ ├───rtc
  480. │ │ ├───sai
  481. │ │ ├───sdhc
  482. │ │ ├───sim
  483. │ │ ├───smc
  484. │ │ ├───uart
  485. │ │ └───wdog
  486. │ └───utilities
  487. │ └───src
  488. └───TARGET_MCU_K64F
  489. ├───device
  490. │ ├───device
  491. │ │ └───MK64F12
  492. │ └───MK64F12
  493. ├───MK64F12
  494. └───TARGET_FRDM
  495. ```
  496. After unpacking exporter ```zip``` file we can go to directory and see files inside MBED_A3 directory:
  497. ```
  498. $ ls
  499. GettingStarted.htm Makefile env main.cpp mbed
  500. ```
  501. Exporter generated for us ```Makefile``` so now we can build our software:
  502. ```
  503. $ make -j 8
  504. .
  505. .
  506. .
  507. text data bss dec hex filename
  508. 29336 184 336 29856 74a0 MBED_A3.elf
  509. ```
  510. We can see root directory of exporter project is now populated with binary files:
  511. * MBED_A3.bin.
  512. * MBED_A3.elf .
  513. * MBED_A3.hex.
  514. You have also map file ```MBED_A3.map``` for your disposal.
  515. ```
  516. $ ls
  517. GettingStarted.htm MBED_A3.bin MBED_A3.elf MBED_A3.hex MBED_A3.map Makefile env main.cpp main.d main.o mbed
  518. ```