Example of blinking LED on LPCXpresso54608 board (OM13092)

LPC-LINK2 Debug Probe Firmware update required with MBED firmware to enable the mbed flash disk interface (board is seen as MSD mass storage device) so drag and drop programming is possible

tested on Windows 7

Based on

https://os.mbed.com/platforms/LPCXpresso54608/

and

https://os.mbed.com/teams/NXP/wiki/Updating-LPCXpresso-firmware

you need to update your LPCXpresso (programmer/debugger) to the latest firmware to enable the mbed flash disk interface.

Note that for LPCXpresso54114 and LPCXpresso546xx boards there is a 2-step programming process (first bootloader needs to be installed, then binary for LPC546xx board).

Detailed guide as follows:

1. Go to LPCScrypt webpage and download its latest version (needs admin rights)

2. Go to DOCUMENTATION section of above link and select “LPC-Link2 Debug Probe Firmware Programming”

3. Configure the selected board to DFU Boot, then connect to the host computer via USB

  • In case of: OM13092/LPCXpresso54806
    • check jumper JP5 “DFU LINK” (needs to be installed) – to download firmware from IDE

4. Download Link2 (LPC432x) Bootloader binary (Use this Bootloader first for boards that require a 2-step update)

  • https://os.mbed.com/media/uploads/mmahadevan/lpc4322_bl_crc.bin
  • Save to directory of LPCScrypt
    • C:\nxp\LPCScrypt_2.0.0_831\probe_firmware\LPCXpressoV2
    • LPCXpressoV2 folder has been chosen because I was able to find an info that debug probe LPC432x is being programmed with LPC432x_IAP_CMSIS_DAP_V5_183.bin file (and this file is in LPCXpressoV2 folder)
      • to confirm that please go to Start -> start typing LPC -> choose “Program LPC-Link2 with CMSIS-DAP”

5. Make a copy of program_CMSIS.cmd file in C:\nxp\LPCScrypt_2.0.0_831\scripts and call it program_CMSIS_mbed_daplink.cmd

  • Open with Notepad++ program_CMSIS_mbed_daplink.cmd file
  • edit:

before
set Link2ImageWild=LPC432x_IAP_CMSIS_DAP_*.bin

after
set Link2ImageWild=lpc4322_bl_*.bin
  • or comment (by adding REM)

before
set Link2ImageWild=LPC432x_IAP_CMSIS_DAP_*.bin

after
REM set Link2ImageWild=LPC432x_IAP_CMSIS_DAP_*.bin
    set Link2ImageWild=lpc4322_bl_*.bin

6. Go to Start -> cmd

  • go to directory

cd C:\nxp\LPCScrypt_2.0.0_831\scripts
  • type command
    • program_CMSIS_mbed_daplink
    • because of changes in program_CMSIS_mbed_daplink.cmd, now file downloaded from MBED called lpc4322_bl_crc.bin is executed
    • Ctrl+C to quit

7. Disconnect the board

8. Remove the jumper JP5 “DFU LINK”

9. Connect again the board

  • In that step board should be seen as MAINTANANCE

10. Go to https://armmbed.github.io/DAPLink/ and type in the box 54608, then you will see firmware file called

  • 0251_lpc4322_lpc54608xpresso_0x10000.bin
  • Download the firmware file
  • Save wherever you want
  • Drag-and-drop the firmware file onto the mounted drive called MAINTANANCE
  • Wait for the file copy operation to complete
  • Power cycle the board. It will now enumerate and mount as DAPLINK or the name of the board

11. Ready for drag and drop programming

stats_report.h

Committer:
marcinch
Date:
2018-12-06
Revision:
4:3bc63d11d829
Parent:
0:09421d80c468

File content as of revision 4:3bc63d11d829:

/* mbed Microcontroller Library
 * Copyright (c) 2018 ARM Limited
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef STATS_REPORT_H
#define STATS_REPORT

#include "mbed.h"

/**
 *  System Reporting library. Provides runtime information on device:
 *      - CPU sleep, idle, and wake times
 *      - Heap and stack usage
 *      - Thread information
 *      - Static system information
 */
class SystemReport {
    mbed_stats_heap_t   heap_stats;
    mbed_stats_cpu_t    cpu_stats;
    mbed_stats_sys_t    sys_stats;

    mbed_stats_thread_t *thread_stats;
    uint8_t   thread_count;
    uint8_t   max_thread_count;
    uint32_t  sample_time_ms;

public:
    /**
     *  SystemReport - Sample rate in ms is required to handle the CPU percent awake logic
     */
    SystemReport(uint32_t sample_rate) : max_thread_count(8), sample_time_ms(sample_rate)
    {
        thread_stats = new mbed_stats_thread_t[max_thread_count];

        // Collect the static system information
        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("Compiler ID: %d \r\n", sys_stats.compiler_id);
        printf("Compiler Version: %ld \r\n", sys_stats.compiler_version);
    }

    ~SystemReport(void)
    {
        free(thread_stats);
    }

    /**
     *  Report on each Mbed OS Platform stats API
     */
    void report_state(void)
    {
        report_cpu_stats();
        report_heap_stats();
        report_thread_stats();

        // Clear next line to separate subsequent report logs
        printf("\r\n");
    }

    /**
     *  Report CPU idle and awake time in terms of percentage
     */
    void report_cpu_stats(void)
    {
        static uint64_t prev_idle_time = 0;

        printf("================= CPU STATS =================\r\n");

        // Collect and print cpu stats
        mbed_stats_cpu_get(&cpu_stats);

        uint64_t diff = (cpu_stats.idle_time - prev_idle_time);
        uint8_t idle = (diff * 100) / (sample_time_ms * 1000);  // usec;
        uint8_t usage = 100 - ((diff * 100) / (sample_time_ms * 1000));  // usec;;
        prev_idle_time = cpu_stats.idle_time;

        printf("Idle: %d%% Usage: %d%% \r\n", idle, usage);
    }

    /**
     *  Report current heap stats. Current heap refers to the current amount of
     *  allocated heap. Max heap refers to the highest amount of heap allocated
     *  since reset.
     */
    void report_heap_stats(void)
    {
        printf("================ HEAP STATS =================\r\n");

        // 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);
    }

    /**
     *  Report active thread stats
     */
    void report_thread_stats(void)
    {
        printf("================ THREAD STATS ===============\r\n");

        // Collect and print running thread stats
        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);
        }
    }
};

#endif // STATS_REPORT_H