Basic

Dependencies:   MQTT

Committer:
lwtroach
Date:
Wed Apr 24 06:13:22 2019 +0000
Branch:
Flash_Exam
Revision:
9:4731ae675a01
Parent:
0:6bdfb6ccd136
When programming the data into flash, the size to API of IAP must be the correct size of data itself, or the algorithm will save the next data after it.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lwtroach 0:6bdfb6ccd136 1 # Getting started example for Mbed OS
lwtroach 0:6bdfb6ccd136 2
lwtroach 0:6bdfb6ccd136 3 This guide reviews the steps required to get Blinky with the addition of dynamic OS statistics working on an Mbed OS platform. (Note: To see a rendered example you can import into the Arm Online Compiler, please see our [quick start](https://os.mbed.com/docs/mbed-os/latest/quick-start/online-with-the-online-compiler.html#importing-the-code).)
lwtroach 0:6bdfb6ccd136 4
lwtroach 0:6bdfb6ccd136 5 Please install [Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
lwtroach 0:6bdfb6ccd136 6
lwtroach 0:6bdfb6ccd136 7 ## Import the example application
lwtroach 0:6bdfb6ccd136 8
lwtroach 0:6bdfb6ccd136 9 From the command-line, import the example:
lwtroach 0:6bdfb6ccd136 10
lwtroach 0:6bdfb6ccd136 11 ```
lwtroach 0:6bdfb6ccd136 12 mbed import mbed-os-example-blinky
lwtroach 0:6bdfb6ccd136 13 cd mbed-os-example-blinky
lwtroach 0:6bdfb6ccd136 14 ```
lwtroach 0:6bdfb6ccd136 15
lwtroach 0:6bdfb6ccd136 16 ### Now compile
lwtroach 0:6bdfb6ccd136 17
lwtroach 0:6bdfb6ccd136 18 Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the Arm Compiler:
lwtroach 0:6bdfb6ccd136 19
lwtroach 0:6bdfb6ccd136 20 ```
lwtroach 0:6bdfb6ccd136 21 mbed compile -m K64F -t ARM
lwtroach 0:6bdfb6ccd136 22 ```
lwtroach 0:6bdfb6ccd136 23
lwtroach 0:6bdfb6ccd136 24 Your PC may take a few minutes to compile your code. At the end, you see the following result:
lwtroach 0:6bdfb6ccd136 25
lwtroach 0:6bdfb6ccd136 26 ```
lwtroach 0:6bdfb6ccd136 27 [snip]
lwtroach 0:6bdfb6ccd136 28
lwtroach 0:6bdfb6ccd136 29 Image: ./BUILD/K64F/GCC_ARM/mbed-os-example-blinky.bin
lwtroach 0:6bdfb6ccd136 30 ```
lwtroach 0:6bdfb6ccd136 31
lwtroach 0:6bdfb6ccd136 32 ### Program your board
lwtroach 0:6bdfb6ccd136 33
lwtroach 0:6bdfb6ccd136 34 1. Connect your Mbed device to the computer over USB.
lwtroach 0:6bdfb6ccd136 35 1. Copy the binary file to the Mbed device.
lwtroach 0:6bdfb6ccd136 36 1. Press the reset button to start the program.
lwtroach 0:6bdfb6ccd136 37
lwtroach 0:6bdfb6ccd136 38 The LED on your platform turns on and off. The main thread will additionally take a snapshot of the device's runtime statistics and display it over serial to your PC. The snapshot includes:
lwtroach 0:6bdfb6ccd136 39
lwtroach 0:6bdfb6ccd136 40 * System Information:
lwtroach 0:6bdfb6ccd136 41 * Mbed OS Version: Will currently default to 999999
lwtroach 0:6bdfb6ccd136 42 * Compiler ID
lwtroach 0:6bdfb6ccd136 43 * ARM = 1
lwtroach 0:6bdfb6ccd136 44 * GCC_ARM = 2
lwtroach 0:6bdfb6ccd136 45 * IAR = 3
lwtroach 0:6bdfb6ccd136 46 * [CPUID Register Information](#cpuid-register-information)
lwtroach 0:6bdfb6ccd136 47 * [Compiler Version](#compiler-version)
lwtroach 0:6bdfb6ccd136 48 * CPU Statistics
lwtroach 0:6bdfb6ccd136 49 * Percentage of runtime that the device has spent awake versus in sleep
lwtroach 0:6bdfb6ccd136 50 * Heap Statistics
lwtroach 0:6bdfb6ccd136 51 * Current heap size
lwtroach 0:6bdfb6ccd136 52 * Max heap size which refers to the largest the heap has grown to
lwtroach 0:6bdfb6ccd136 53 * Thread Statistics
lwtroach 0:6bdfb6ccd136 54 * Provides information on all running threads in the OS including
lwtroach 0:6bdfb6ccd136 55 * Thread ID
lwtroach 0:6bdfb6ccd136 56 * Thread Name
lwtroach 0:6bdfb6ccd136 57 * Thread State
lwtroach 0:6bdfb6ccd136 58 * Thread Priority
lwtroach 0:6bdfb6ccd136 59 * Thread Stack Size
lwtroach 0:6bdfb6ccd136 60 * Thread Stack Space
lwtroach 0:6bdfb6ccd136 61
lwtroach 0:6bdfb6ccd136 62 #### Compiler Version
lwtroach 0:6bdfb6ccd136 63
lwtroach 0:6bdfb6ccd136 64 | Compiler | Version Layout |
lwtroach 0:6bdfb6ccd136 65 | -------- | -------------- |
lwtroach 0:6bdfb6ccd136 66 | ARM | PVVbbbb (P = Major; VV = Minor; bbbb = build number) |
lwtroach 0:6bdfb6ccd136 67 | GCC | VVRRPP (VV = Version; RR = Revision; PP = Patch) |
lwtroach 0:6bdfb6ccd136 68 | IAR | VRRRPPP (V = Version; RRR = Revision; PPP = Patch) |
lwtroach 0:6bdfb6ccd136 69
lwtroach 0:6bdfb6ccd136 70 #### CPUID Register Information
lwtroach 0:6bdfb6ccd136 71
lwtroach 0:6bdfb6ccd136 72 | Bit Field | Field Description | Values |
lwtroach 0:6bdfb6ccd136 73 | --------- | ----------------- | ------ |
lwtroach 0:6bdfb6ccd136 74 |[31:24] | Implementer | 0x41 = ARM |
lwtroach 0:6bdfb6ccd136 75 |[23:20] | Variant | Major revision 0x0 = Revision 0 |
lwtroach 0:6bdfb6ccd136 76 |[19:16] | Architecture | 0xC = Baseline Architecture |
lwtroach 0:6bdfb6ccd136 77 | | | 0xF = Constant (Mainline Architecture) |
lwtroach 0:6bdfb6ccd136 78 |[15:4] | Part Number | 0xC20 = Cortex-M0 |
lwtroach 0:6bdfb6ccd136 79 | | | 0xC60 = Cortex-M0+ |
lwtroach 0:6bdfb6ccd136 80 | | | 0xC23 = Cortex-M3 |
lwtroach 0:6bdfb6ccd136 81 | | | 0xC24 = Cortex-M4 |
lwtroach 0:6bdfb6ccd136 82 | | | 0xC27 = Cortex-M7 |
lwtroach 0:6bdfb6ccd136 83 | | | 0xD20 = Cortex-M23 |
lwtroach 0:6bdfb6ccd136 84 | | | 0xD21 = Cortex-M33 |
lwtroach 0:6bdfb6ccd136 85 |[3:0] | Revision | Minor revision: 0x1 = Patch 1 |
lwtroach 0:6bdfb6ccd136 86
lwtroach 0:6bdfb6ccd136 87
lwtroach 0:6bdfb6ccd136 88
lwtroach 0:6bdfb6ccd136 89 You can view individual examples and additional API information of the statistics collection tools at the bottom of the page in the [related links section](#related-links).
lwtroach 0:6bdfb6ccd136 90
lwtroach 0:6bdfb6ccd136 91
lwtroach 0:6bdfb6ccd136 92 ### Output
lwtroach 0:6bdfb6ccd136 93
lwtroach 0:6bdfb6ccd136 94 To view the serial output you can use any terminal client of your choosing such as [PuTTY](http://www.putty.org/) or [CoolTerm](http://freeware.the-meiers.org/). Unless otherwise specified, printf defaults to a baud rate of 9600 on Mbed OS.
lwtroach 0:6bdfb6ccd136 95
lwtroach 0:6bdfb6ccd136 96 You can find more information on the Mbed OS configuration tools and serial communication in Mbed OS in the related [related links section](#related-links).
lwtroach 0:6bdfb6ccd136 97
lwtroach 0:6bdfb6ccd136 98 The output should contain the following block transmitted at the blinking LED frequency (actual values may vary depending on your target, build profile, and toolchain):
lwtroach 0:6bdfb6ccd136 99
lwtroach 0:6bdfb6ccd136 100 ```
lwtroach 0:6bdfb6ccd136 101 =============================== SYSTEM INFO ================================
lwtroach 0:6bdfb6ccd136 102 Mbed OS Version: 999999
lwtroach 0:6bdfb6ccd136 103 CPU ID: 0x410fc241
lwtroach 0:6bdfb6ccd136 104 Compiler ID: 2
lwtroach 0:6bdfb6ccd136 105 Compiler Version: 60300
lwtroach 0:6bdfb6ccd136 106 RAM0: Start 0x20000000 Size: 0x30000
lwtroach 0:6bdfb6ccd136 107 RAM1: Start 0x1fff0000 Size: 0x10000
lwtroach 0:6bdfb6ccd136 108 ROM0: Start 0x0 Size: 0x100000
lwtroach 0:6bdfb6ccd136 109 ================= CPU STATS =================
lwtroach 0:6bdfb6ccd136 110 Idle: 98% Usage: 2%
lwtroach 0:6bdfb6ccd136 111 ================ HEAP STATS =================
lwtroach 0:6bdfb6ccd136 112 Current heap: 1096
lwtroach 0:6bdfb6ccd136 113 Max heap size: 1096
lwtroach 0:6bdfb6ccd136 114 ================ THREAD STATS ===============
lwtroach 0:6bdfb6ccd136 115 ID: 0x20001eac
lwtroach 0:6bdfb6ccd136 116 Name: main_thread
lwtroach 0:6bdfb6ccd136 117 State: 2
lwtroach 0:6bdfb6ccd136 118 Priority: 24
lwtroach 0:6bdfb6ccd136 119 Stack Size: 4096
lwtroach 0:6bdfb6ccd136 120 Stack Space: 3296
lwtroach 0:6bdfb6ccd136 121
lwtroach 0:6bdfb6ccd136 122 ID: 0x20000f5c
lwtroach 0:6bdfb6ccd136 123 Name: idle_thread
lwtroach 0:6bdfb6ccd136 124 State: 1
lwtroach 0:6bdfb6ccd136 125 Priority: 1
lwtroach 0:6bdfb6ccd136 126 Stack Size: 512
lwtroach 0:6bdfb6ccd136 127 Stack Space: 352
lwtroach 0:6bdfb6ccd136 128
lwtroach 0:6bdfb6ccd136 129 ID: 0x20000f18
lwtroach 0:6bdfb6ccd136 130 Name: timer_thread
lwtroach 0:6bdfb6ccd136 131 State: 3
lwtroach 0:6bdfb6ccd136 132 Priority: 40
lwtroach 0:6bdfb6ccd136 133 Stack Size: 768
lwtroach 0:6bdfb6ccd136 134 Stack Space: 664
lwtroach 0:6bdfb6ccd136 135
lwtroach 0:6bdfb6ccd136 136 ```
lwtroach 0:6bdfb6ccd136 137
lwtroach 0:6bdfb6ccd136 138 ## Troubleshooting
lwtroach 0:6bdfb6ccd136 139
lwtroach 0:6bdfb6ccd136 140 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.
lwtroach 0:6bdfb6ccd136 141
lwtroach 0:6bdfb6ccd136 142 ## Related Links
lwtroach 0:6bdfb6ccd136 143
lwtroach 0:6bdfb6ccd136 144 * [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html)
lwtroach 0:6bdfb6ccd136 145 * [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html)
lwtroach 0:6bdfb6ccd136 146 * [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html)
lwtroach 0:6bdfb6ccd136 147
lwtroach 0:6bdfb6ccd136 148 ### License and contributions
lwtroach 0:6bdfb6ccd136 149
lwtroach 0:6bdfb6ccd136 150 The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see contributing.md for more info.
lwtroach 0:6bdfb6ccd136 151
lwtroach 0:6bdfb6ccd136 152 This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.