This is a very simple guide, reviewing the steps required to get Blinky working on an Mbed OS platform.
Mbed OS Blinky
This example shows the use of a DigitalOut object to represent an LED and use of the nonblocking Thread::wait()
call. Using nonblocking calls is good practice because Mbed OS can schedule and run other threads while the first thread is waiting.
Building this example
Building with Arm Mbed CLI
To use Mbed CLI to build this example, follow the instructions in the documentation. The instructions here relate to using the Arm Online Compiler.
To use the Online Compiler, import this code into the Online Compiler, and select your platform from the top right. Compile the code using the compile button, load it onto your board and press the reset button on the board. The code will run on the board, and you will see the LED blink.
You can find more instructions for using the Mbed Online Compiler in the documentation.
Revision 98:f2d7e14c84a1, committed 2019-09-04
- Comitter:
- mbed_official
- Date:
- Wed Sep 04 12:00:04 2019 +0100
- Parent:
- 97:d180a47a5804
- Child:
- 99:394543729870
- Commit message:
- Merge pull request #186 from hugueskamba/hk-fix-warnings
Clear all warnings generated by the example project files.
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-blinky
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
stats_report.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Jul 23 12:00:36 2019 +0100 +++ b/main.cpp Wed Sep 04 12:00:04 2019 +0100 @@ -4,6 +4,7 @@ */ #include "mbed.h" +#include "ThisThread.h" #include "stats_report.h" DigitalOut led1(LED1); @@ -20,7 +21,7 @@ while (true) { // Blink LED and wait 0.5 seconds led1 = !led1; - wait_ms(SLEEP_TIME); + ThisThread::sleep_for(SLEEP_TIME); if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) { // Following the main thread wait, report on the current system status
--- a/stats_report.h Tue Jul 23 12:00:36 2019 +0100 +++ b/stats_report.h Wed Sep 04 12:00:04 2019 +0100 @@ -4,8 +4,9 @@ */ #ifndef STATS_REPORT_H -#define STATS_REPORT +#define STATS_REPORT_H +#include <inttypes.h> #include "mbed.h" /** @@ -37,19 +38,19 @@ mbed_stats_sys_get(&sys_stats); printf("=============================== SYSTEM INFO ================================\r\n"); - printf("Mbed OS Version: %ld \r\n", sys_stats.os_version); - printf("CPU ID: 0x%lx \r\n", sys_stats.cpu_id); + printf("Mbed OS Version: %" PRIu32 " \r\n", sys_stats.os_version); + printf("CPU ID: 0x%" PRIx32 " \r\n", sys_stats.cpu_id); printf("Compiler ID: %d \r\n", sys_stats.compiler_id); - printf("Compiler Version: %ld \r\n", sys_stats.compiler_version); + printf("Compiler Version: %" PRIu32 " \r\n", sys_stats.compiler_version); for (int i = 0; i < MBED_MAX_MEM_REGIONS; i++) { if (sys_stats.ram_size[i] != 0) { - printf("RAM%d: Start 0x%lx Size: 0x%lx \r\n", i, sys_stats.ram_start[i], sys_stats.ram_size[i]); + printf("RAM%d: Start 0x%" PRIx32 " Size: 0x%" PRIx32 " \r\n", i, sys_stats.ram_start[i], sys_stats.ram_size[i]); } } for (int i = 0; i < MBED_MAX_MEM_REGIONS; i++) { if (sys_stats.rom_size[i] != 0) { - printf("ROM%d: Start 0x%lx Size: 0x%lx \r\n", i, sys_stats.rom_start[i], sys_stats.rom_size[i]); + printf("ROM%d: Start 0x%" PRIx32 " Size: 0x%" PRIx32 " \r\n", i, sys_stats.rom_start[i], sys_stats.rom_size[i]); } } } @@ -104,8 +105,8 @@ // Collect and print heap stats mbed_stats_heap_get(&heap_stats); - printf("Current heap: %lu\r\n", heap_stats.current_size); - printf("Max heap size: %lu\r\n", heap_stats.max_size); + printf("Current heap: %" PRIu32 "\r\n", heap_stats.current_size); + printf("Max heap size: %" PRIu32 "\r\n", heap_stats.max_size); } /** @@ -119,12 +120,12 @@ int count = mbed_stats_thread_get_each(thread_stats, max_thread_count); for (int i = 0; i < count; i++) { - printf("ID: 0x%lx \r\n", thread_stats[i].id); - printf("Name: %s \r\n", thread_stats[i].name); - printf("State: %ld \r\n", thread_stats[i].state); - printf("Priority: %ld \r\n", thread_stats[i].priority); - printf("Stack Size: %ld \r\n", thread_stats[i].stack_size); - printf("Stack Space: %ld \r\n", thread_stats[i].stack_space); + printf("ID: 0x%" PRIx32 " \r\n", thread_stats[i].id); + printf("Name: %s \r\n", thread_stats[i].name); + printf("State: %" PRIu32 " \r\n", thread_stats[i].state); + printf("Priority: %" PRIu32 " \r\n", thread_stats[i].priority); + printf("Stack Size: %" PRIu32 " \r\n", thread_stats[i].stack_size); + printf("Stack Space: %" PRIu32 " \r\n", thread_stats[i].stack_space); } } };