Ejemplo blinky mbed studio (mbed 6)

Committer:
ezebrizzio
Date:
Wed Aug 12 00:06:36 2020 -0300
Revision:
2:e593110be031
Parent:
0:5012a67cbe16
agrega unos printf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ezebrizzio 0:5012a67cbe16 1 ![](./resources/official_armmbed_example_badge.png)
ezebrizzio 0:5012a67cbe16 2 # Bare metal blinky Mbed OS example
ezebrizzio 0:5012a67cbe16 3
ezebrizzio 0:5012a67cbe16 4 This example shows how to achieve memory optimizations in Mbed OS. Starting with a blinky application, the example illustrates how to enable the bare metal profile and further memory optimizations.
ezebrizzio 0:5012a67cbe16 5
ezebrizzio 0:5012a67cbe16 6 You can build this project with all supported [Mbed OS build tools](https://os.mbed.com/docs/mbed-os/latest/tools/index.html). However, this example project specifically refers to the command-line interface tool [Arm Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
ezebrizzio 0:5012a67cbe16 7
ezebrizzio 0:5012a67cbe16 8 1. Install Mbed CLI.
ezebrizzio 0:5012a67cbe16 9 1. From the command-line, import the example: `mbed import mbed-os-example-blinky-baremetal`
ezebrizzio 0:5012a67cbe16 10 1. Change the current directory to where the project was imported.
ezebrizzio 0:5012a67cbe16 11
ezebrizzio 0:5012a67cbe16 12 ## Application functionality
ezebrizzio 0:5012a67cbe16 13
ezebrizzio 0:5012a67cbe16 14 The `main()` function toggles the state of a digital output connected to an LED on the board.
ezebrizzio 0:5012a67cbe16 15
ezebrizzio 0:5012a67cbe16 16 ## Building and running
ezebrizzio 0:5012a67cbe16 17
ezebrizzio 0:5012a67cbe16 18 1. Connect a USB cable between the USB port on the target and the host computer.
ezebrizzio 0:5012a67cbe16 19 1. Run the following command to build the example project, program the microcontroller flash memory, and open a serial terminal:
ezebrizzio 0:5012a67cbe16 20
ezebrizzio 0:5012a67cbe16 21 ```
ezebrizzio 0:5012a67cbe16 22 $ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash --sterm
ezebrizzio 0:5012a67cbe16 23 ```
ezebrizzio 0:5012a67cbe16 24
ezebrizzio 0:5012a67cbe16 25
ezebrizzio 0:5012a67cbe16 26 Your PC may take a few minutes to compile your code.
ezebrizzio 0:5012a67cbe16 27
ezebrizzio 0:5012a67cbe16 28 The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-blinky-baremetal.bin`.
ezebrizzio 0:5012a67cbe16 29
ezebrizzio 0:5012a67cbe16 30 Alternatively, you can manually copy the binary to the target, which gets mounted on the host computer through USB.
ezebrizzio 0:5012a67cbe16 31
ezebrizzio 0:5012a67cbe16 32 Depending on the target, you can build the example project with the `GCC_ARM`, `ARM` or `IAR` toolchain. After installing Arm Mbed CLI, run the command below to determine which toolchain supports your target:
ezebrizzio 0:5012a67cbe16 33
ezebrizzio 0:5012a67cbe16 34 ```
ezebrizzio 0:5012a67cbe16 35 $ mbed compile -S
ezebrizzio 0:5012a67cbe16 36 ```
ezebrizzio 0:5012a67cbe16 37
ezebrizzio 0:5012a67cbe16 38 ## Expected output
ezebrizzio 0:5012a67cbe16 39
ezebrizzio 0:5012a67cbe16 40 The LED on your target turns on and off every 500 milliseconds, and the serial terminal shows an output similar to:
ezebrizzio 0:5012a67cbe16 41
ezebrizzio 0:5012a67cbe16 42 ```
ezebrizzio 0:5012a67cbe16 43 --- Terminal on /dev/tty.usbmodem21102 - 9600,8,N,1 ---
ezebrizzio 0:5012a67cbe16 44 This is the bare metal blinky example running on Mbed OS 99.99.99.
ezebrizzio 0:5012a67cbe16 45 ```
ezebrizzio 0:5012a67cbe16 46
ezebrizzio 0:5012a67cbe16 47 ## Configuring the application
ezebrizzio 0:5012a67cbe16 48
ezebrizzio 0:5012a67cbe16 49 ### The bare metal profile
ezebrizzio 0:5012a67cbe16 50
ezebrizzio 0:5012a67cbe16 51 The bare metal profile is a configuration of Mbed OS that excludes the RTOS, as well as other features. We designed it specifically for ultraconstrained devices because it gives you more control over the system. For more details, please see [the bare metal documentation](https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-bare-metal.html)
ezebrizzio 0:5012a67cbe16 52
ezebrizzio 0:5012a67cbe16 53 To build with the bare metal profile, the application configuration file must contain:
ezebrizzio 0:5012a67cbe16 54
ezebrizzio 0:5012a67cbe16 55 ```json
ezebrizzio 0:5012a67cbe16 56 {
ezebrizzio 0:5012a67cbe16 57 "requires": ["bare-metal"]
ezebrizzio 0:5012a67cbe16 58 }
ezebrizzio 0:5012a67cbe16 59 ```
ezebrizzio 0:5012a67cbe16 60
ezebrizzio 0:5012a67cbe16 61 ### Futher optimizations
ezebrizzio 0:5012a67cbe16 62 Some of the configurations shown below are already set by default in `targets/targets.json` and `platform/mbed_lib.json`.
ezebrizzio 0:5012a67cbe16 63 #### Linking with smaller C libraries
ezebrizzio 0:5012a67cbe16 64
ezebrizzio 0:5012a67cbe16 65 Both the `ARM` and `GCC_ARM` toolchains support optimized versions of their C standard libraries, microlib and newlib-nano. We recommend using them with the bare metal profile.
ezebrizzio 0:5012a67cbe16 66
ezebrizzio 0:5012a67cbe16 67 To build with the smaller C libraries, modify the application configuration file:
ezebrizzio 0:5012a67cbe16 68
ezebrizzio 0:5012a67cbe16 69 ```json
ezebrizzio 0:5012a67cbe16 70 {
ezebrizzio 0:5012a67cbe16 71 "target_overrides": {
ezebrizzio 0:5012a67cbe16 72 "*": {
ezebrizzio 0:5012a67cbe16 73 "target.c_lib": "small"
ezebrizzio 0:5012a67cbe16 74 }
ezebrizzio 0:5012a67cbe16 75 }
ezebrizzio 0:5012a67cbe16 76 }
ezebrizzio 0:5012a67cbe16 77 ```
ezebrizzio 0:5012a67cbe16 78
ezebrizzio 0:5012a67cbe16 79 The build system reverts to the standard C library if support for the small C library is not enabled for your target. You can find more information [here]( https://github.com/ARMmbed/mbed-os-5-docs/blob/development/docs/program-setup/bare_metal/c_small_libs.md).
ezebrizzio 0:5012a67cbe16 80
ezebrizzio 0:5012a67cbe16 81 #### Using Mbed minimal printf library
ezebrizzio 0:5012a67cbe16 82
ezebrizzio 0:5012a67cbe16 83 Mbed OS offers a smaller `printf()` alternative. The [minimal printf](https://github.com/ARMmbed/mbed-os/blob/master/platform/source/minimal-printf/README.md) library implements a subset of the `v/s/f/printf` function family, and you can disable floating points to further reduce code size.
ezebrizzio 0:5012a67cbe16 84
ezebrizzio 0:5012a67cbe16 85 To build with the minimal printf library and disable floating points printing, you need to modify the application configuration file:
ezebrizzio 0:5012a67cbe16 86
ezebrizzio 0:5012a67cbe16 87 ```json
ezebrizzio 0:5012a67cbe16 88 {
ezebrizzio 0:5012a67cbe16 89 "target_overrides": {
ezebrizzio 0:5012a67cbe16 90 "*": {
ezebrizzio 0:5012a67cbe16 91 "target.printf_lib": "minimal-printf",
ezebrizzio 0:5012a67cbe16 92 "platform.minimal-printf-enable-floating-point": false
ezebrizzio 0:5012a67cbe16 93 }
ezebrizzio 0:5012a67cbe16 94 }
ezebrizzio 0:5012a67cbe16 95 }
ezebrizzio 0:5012a67cbe16 96 ```
ezebrizzio 0:5012a67cbe16 97
ezebrizzio 0:5012a67cbe16 98 Further optimizations are possible. For more details, please see the minimal printf README.
ezebrizzio 0:5012a67cbe16 99
ezebrizzio 0:5012a67cbe16 100 #### Using a minimal console
ezebrizzio 0:5012a67cbe16 101
ezebrizzio 0:5012a67cbe16 102 If your application only needs unbuffered I/O operations, you can save additional memory by using a configuration of the platform library, which removes file handling functionality from the [system I/O retarget code](https://github.com/ARMmbed/mbed-os/blob/master/platform/source/mbed_retarget.cpp).
ezebrizzio 0:5012a67cbe16 103
ezebrizzio 0:5012a67cbe16 104 To build with the minimal console functionality, modify the application configuration file:
ezebrizzio 0:5012a67cbe16 105
ezebrizzio 0:5012a67cbe16 106 ```json
ezebrizzio 0:5012a67cbe16 107 {
ezebrizzio 0:5012a67cbe16 108 "target_overrides": {
ezebrizzio 0:5012a67cbe16 109 "*": {
ezebrizzio 0:5012a67cbe16 110 "platform.stdio-minimal-console-only": true
ezebrizzio 0:5012a67cbe16 111 }
ezebrizzio 0:5012a67cbe16 112 }
ezebrizzio 0:5012a67cbe16 113 }
ezebrizzio 0:5012a67cbe16 114 ```
ezebrizzio 0:5012a67cbe16 115
ezebrizzio 0:5012a67cbe16 116 #### Memory comparison
ezebrizzio 0:5012a67cbe16 117
ezebrizzio 0:5012a67cbe16 118 The below table shows the result for the blinky bare metal application compiled with the release profile on K64F for the GCC_ARM toolchain.
ezebrizzio 0:5012a67cbe16 119
ezebrizzio 0:5012a67cbe16 120 The baseline configuration used is the blinky bare metal application built with the standard C library.
ezebrizzio 0:5012a67cbe16 121
ezebrizzio 0:5012a67cbe16 122 Mbed OS release: mbed-os-6.0.0-alpha-2
ezebrizzio 0:5012a67cbe16 123
ezebrizzio 0:5012a67cbe16 124 |Standard C lib|Small C lib|Minimal printf|Minimal console|RAM|Flash|
ezebrizzio 0:5012a67cbe16 125 | :---: | :---: | :---: | :---: | :---: | :---: |
ezebrizzio 0:5012a67cbe16 126 | X | | | | 0 | 0 |
ezebrizzio 0:5012a67cbe16 127 | | X | | | -2,592 | -28,581 |
ezebrizzio 0:5012a67cbe16 128 | | X | X | | -2,592 | -29,918 |
ezebrizzio 0:5012a67cbe16 129 | | X | X | X | -2,592 | -30,810 |
ezebrizzio 0:5012a67cbe16 130
ezebrizzio 0:5012a67cbe16 131 ## Troubleshooting
ezebrizzio 0:5012a67cbe16 132
ezebrizzio 0:5012a67cbe16 133 If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
ezebrizzio 0:5012a67cbe16 134
ezebrizzio 0:5012a67cbe16 135 ## Related links
ezebrizzio 0:5012a67cbe16 136
ezebrizzio 0:5012a67cbe16 137 - [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-bare-metal.html).
ezebrizzio 0:5012a67cbe16 138 - [Mbed OS configuration](https://os.mbed.com/docs/latest/reference/configuration.html).
ezebrizzio 0:5012a67cbe16 139 - [Mbed OS serial communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html).
ezebrizzio 0:5012a67cbe16 140 - [Mbed boards](https://os.mbed.com/platforms/).
ezebrizzio 0:5012a67cbe16 141
ezebrizzio 0:5012a67cbe16 142 ### License and contributions
ezebrizzio 0:5012a67cbe16 143
ezebrizzio 0:5012a67cbe16 144 The software is provided under the Apache-2.0 license. Contributions to this project are accepted under the same license. Please see contributing.md for more information.
ezebrizzio 0:5012a67cbe16 145
ezebrizzio 0:5012a67cbe16 146 This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.