Application to demonstrate Mbed-OS error handling and error coding APIs

Homepage

Example application to demonstrate Mbed-OS error handling

This example demonstrates how to use the Mbed OS error handling API.

This example program can be run on any Mbed-Enabled device. For demonstration purposes, the below documentation uses K64F as the test device. One of the functionality with error handling feature is to save the error log in a file and that requires a storage support on the device. The example program does have sample code to invoke that functionality, but you will need to pass a special flag as part of your command if you want to test that functionality.

Note that the example application mostly uses MBED_WARNING macros to demostrate the usage. Usage of MBED_ERROR macros are identical but the behavior is different in that calling MBED_ERROR macros halt the application after the recording the error. So, in this test application MBED_ERROR() call is the last call we make.

Setup

By importing into Mbed CLI

Click `Import this compiler` button and choose `Import with Mbed CLI`.

Compile the application.

A binary is generated at the end of the build process.

By cloning the example locally

Setup your Mbed development environment as described in - https:os.mbed.com/docs/latest/tutorials/your-first-program.html.

From the command-line, clone the example:

git clone https://github.com/ARMmbed/mbed-os-example-error-handling

cd mbed-os-example-error-handling

mbed deploy

Compile the example(if building locally)

Compile the application as below using ARM compiler. If you want to use GCC or IAR toolchains, use GCC_ARM or IAR for -t option.

mbed compile -m K64F -t ARM

If you want to test the "saving error history to file" functionality you can build the program as below provided you have a SD card on the device. mbed compile -t arm -m k64f -DMBED_TEST_SIM_BLOCKDEVICE=SDBlockDevice

You can also test this functionality using a simulated block device as mbed compile -t arm -m k64f -DMBED_TEST_SIM_BLOCKDEVICE=HeapBlockDevice

This may take few minutes and once its successfully completed it would generate the output as below.

Link: mbed-os-example-error-handling Elf2Bin: mbed-os-example-error-handling

+------------------+-------+-------+------+
| Module           | .text | .data | .bss |
+------------------+-------+-------+------+
| [lib]\c_w.l      | 12963 |    16 |  348 |
| [lib]\cpprt_w.l  |    42 |     0 |    0 |
| [lib]\fz_wm.l    |    18 |     0 |    0 |
| [lib]\m_wm.l     |    48 |     0 |    0 |
| anon$$obj.o      |    32 |     0 | 1024 |
| main.o           |  2057 |     0 |  268 |
| mbed-os\drivers  |   130 |     0 |    0 |
| mbed-os\features | 16840 |     0 |  304 |
| mbed-os\hal      |  1660 |    30 |   64 |
| mbed-os\platform |  4565 |   104 |  604 |
| mbed-os\rtos     | 14646 |  2310 | 4592 |
| mbed-os\targets  |  9249 |   104 |  324 |
| Subtotals        | 62250 |  2564 | 7528 |
+------------------+-------+-------+------+
Total Static RAM memory (data + bss): 10092 bytes
Total Flash memory (text + data): 64814 bytes

Image: .\BUILD\k64f\arm\mbed-os-example-error-handling.bin

Run the example

1. Connect a K64F device to your pc 1. Open a serial terminal connected to the device 1. Copy the binary file to the device. 1. Reset the device by pressing the reset button to start the program.

The output should look similar to below:

Error Handling and Error Coding Demo...
Error Status and Context capture successful
Error history capture successful
Error hook successful


++ MbedOS Error Info ++
Error Status: 0x80000110 Code: 272 Entity: 0
Error Message: System type error
Location: 0x61f5
Error Value: 0xdeaddead
Current Thread: Id: 0x20001f70 Entry: 0x7fa5 StackSize: 0x1000 StackMem: 0x20000f70 SP: 0x20001ed8
-- MbedOS Error Info --

If you have enabled testing for file saving feature, the output should look similar to below.

Error Handling and Error Coding Demo...
Error Status and Context capture successful
Error history capture successful
First Error: Status:0x80000101 ThreadId:0x20002068 Address:0xb233 Value:0x1234

Last Error: Status:0x80ff0107 ThreadId:0x20002068 Address:0xb233 Value:0x5

3: Status:0x80ff0107 ThreadId:0x20002068 Address:0xb233 Value:0x5

2: Status:0x80ff0108 ThreadId:0x20002068 Address:0xb233 Value:0x4

1: Status:0x80ff0109 ThreadId:0x20002068 Address:0xb233 Value:0x3

0: Status:0x80ff010c ThreadId:0x20002068 Address:0xb233 Value:0x2

Saving error history to filesystem successful
Error hook successful


++ MbedOS Error Info ++
Error Status: 0x80000110 Code: 272 Entity: 0
Error Message: System type error
Location: 0xaa79
Error Value: 0xdeaddead
Current Thread: Id: 0x20002068 Entry: 0xc97d StackSize: 0x1000 StackMem: 0x20001068 SP: 0x20001fd0
-- MbedOS Error Info --

All wikipages