Myself and others new to mbed having trouble understanding the various arcane requirements. Adding a mbed_app.json file to enable a library feature instead of using a #define is one of them. Sharing this to help others.

Dependencies:   max32630fthr USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // Unless otherwise noted in individual libraries, this code is for educational
00002 // purposes only with no guaranties - use at your own risk. This file is 
00003 // declared to be completely in the public domain.
00004 
00005 #include "mbed.h"
00006 #include "max32630fthr.h"
00007 #include "USBSerial.h"
00008 
00009 // for stats
00010 #include "platform/mbed_assert.h"
00011 #include "platform/mbed_debug.h"
00012 #include "platform/mbed_error.h"
00013 
00014 // define all stats enabled before including the header
00015 //#define MBED_ALL_STATS_ENABLED 1
00016 // *** using mos 5.11.5 (as 12.0 does not compile even blinky) does not work as expected. must include mbed_app.json file at same
00017 // *** directory level as main.cpp with:
00018 /*
00019 {
00020     "target_overrides": {
00021         "*": {
00022             "platform.all-stats-enabled": true
00023         }
00024     }
00025 }
00026 */
00027 #include "platform/mbed_stats.h"
00028 
00029 #define MAX_THREAD_INFO 10
00030 
00031 // global vars
00032 mbed_stats_sys_t sys_info;
00033 mbed_stats_cpu_t cpu_info;
00034 mbed_stats_heap_t heap_info;
00035 mbed_stats_stack_t stack_info[ MAX_THREAD_INFO ];
00036 
00037 // platform specific
00038 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
00039 
00040 // Virtual serial port over USB
00041 USBSerial microUSB; 
00042 
00043 // RTOS is enabled
00044 int main()
00045 {
00046     // wait until user ready
00047     while (!microUSB.terminal_connected){
00048         Thread::yield();
00049     }
00050 
00051 
00052 // stats
00053     microUSB.printf("\n\nSystem:");
00054     microUSB.printf("\n---");
00055     mbed_stats_sys_get(&sys_info);
00056     microUSB.printf("\n\tmbed os version: %d", sys_info.os_version);
00057     microUSB.printf("\n\tCPU ID: %d", sys_info.cpu_id);
00058     microUSB.printf("\n\tCompiler ID: ");
00059     switch(sys_info.compiler_id){
00060         case ARM:       microUSB.printf("ARM"); break;
00061         case GCC_ARM:   microUSB.printf("GCC_ARM"); break;
00062         case IAR:       microUSB.printf("IAR"); break;
00063         default:        microUSB.printf("UNKNOWN: %d", sys_info.compiler_id); break;
00064     }
00065     microUSB.printf("\n\tCompiler version: %d", sys_info.compiler_version);
00066     
00067     // times are sourced in uSec, converted to seconds
00068     microUSB.printf("\n\nCPU (seconds):");
00069     microUSB.printf("\n---");
00070     mbed_stats_cpu_get(&cpu_info);
00071     microUSB.printf("\n\tUp time sec: %0.6f", cpu_info.uptime / 1000000.0);
00072     microUSB.printf("\n\tIdle time: %0.6f", cpu_info.idle_time / 1000000.0);
00073     microUSB.printf("\n\tSleep time: %0.6f", cpu_info.sleep_time / 1000000.0);
00074     microUSB.printf("\n\tDeep sleep time: %0.6f", cpu_info.deep_sleep_time / 1000000.0);
00075     
00076     microUSB.printf("\n\nMemory:");
00077     microUSB.printf("\n---");
00078     mbed_stats_heap_get( &heap_info );
00079     microUSB.printf("\n\tBytes allocated currently: %d", heap_info.current_size);
00080     microUSB.printf("\n\tMax bytes allocated at a given time: %d", heap_info.max_size);
00081     microUSB.printf("\n\tCumulative sum of bytes ever allocated: %d", heap_info.total_size);
00082     microUSB.printf("\n\tCurrent number of bytes allocated for the heap: %d", heap_info.reserved_size);
00083     microUSB.printf("\n\tCurrent number of allocations: %d", heap_info.alloc_cnt);
00084     microUSB.printf("\n\tNumber of failed allocations: %d", heap_info.alloc_fail_cnt);
00085     
00086     mbed_stats_stack_get( &stack_info[0] );
00087     microUSB.printf("\n\nCumulative Stack:");
00088     microUSB.printf("\n---");
00089     microUSB.printf("\n\tMaximum number of bytes used on the stack: %d", stack_info[0].max_size);
00090     microUSB.printf("\n\tCurrent number of bytes allocated for the stack: %d", stack_info[0].reserved_size);
00091     microUSB.printf("\n\tNumber of stacks stats accumulated in the structure: %d", stack_info[0].stack_cnt);
00092     
00093     mbed_stats_stack_get_each( stack_info, MAX_THREAD_INFO );
00094     microUSB.printf("\n\nThread Stack:");
00095     microUSB.printf("\n---");
00096     for(int i=0;i < MAX_THREAD_INFO; i++) {
00097         if(stack_info[i].thread_id != 0) {
00098             microUSB.printf("\n\tThread: %d", i);
00099             microUSB.printf("\n\t\tThread Id: 0x%08X", stack_info[i].thread_id);
00100             microUSB.printf("\n\t\tMaximum number of bytes used on the stack: %d", stack_info[i].max_size);
00101             microUSB.printf("\n\t\tCurrent number of bytes allocated for the stack: %d", stack_info[i].reserved_size);
00102             microUSB.printf("\n\t\tNumber of stacks stats accumulated in the structure: %d", stack_info[i].stack_cnt); 
00103             microUSB.printf("\n---");
00104         }        
00105     }
00106     
00107     microUSB.printf("\n===\n\n");
00108 
00109 }
00110