-
Notifications
You must be signed in to change notification settings - Fork 2
MCX Lab Heart rate demo
In this lab, you will learn:
- How to use Application Code Hub to import an example into the VS Code workspace
- How to build, clean, debug, and run the example
- How to connect the Serial Monitor for UART console
- How FreeMASTER can be used as a real-time debug monitor and data visualization tool
The NXP Application Code Hub provides a complete example of how to use the MCXA-153 microcontroller in a Heart Rate and SPO2 monitor application. This lab will walk through the steps to import, build, program and debug the example. The final section of the lab shows how to use FreeMASTER as a data-visualization tool for the acquired sensor data from the FRDM-MCXA153 evaluation board.
The prework instructions should be completed before starting this lab. The instructions walk through the installation for the required software.
After finishing, the system should have the following:
- Visual Studio Code - Base software tool distributed by Microsoft
- MCUXpresso for Visual Studio Code Extension - NXP developed extension to configure VS Code for embedded MCU development
- MCXUXpresso Installer - required to install 3rd party tools for MCUXpresso projects to correctly import/build/debug.
- FRDM-MCXA153 SDK 2.14.0 - required to provide software libraries for middleware and drivers referenced in the example
- Link to Installation and Preparation
The Application Code Hub (ACH) repository enables engineers to easily find microcontroller software examples, code snippets, application software packs and demos developed by NXP in-house experts. This space provides a quick, easy and consistent way to find microcontroller applications. Find more information at www.nxp.com/ach
The MCUXpresso for VS Code extension has integrated the Application Code Hub into the development environment. The extension provides an Import Wizard to simplify adding examples from the Application Code Hub. The wizard handles the steps required to clone the selected project repository.
NOTE: The Application Code Hub examples are delivered from GitHub at www.github.com/nxp-appcodehub The integrated viewer makes it easier for customers to explore. Alternatively, customers can manually add the projects using traditional methods to clone GitHub repositories and importing the local project folder.
Here are the steps to import a new Example from the Application Code Hub:
-
Go to the Quick Start Panel
-
Select Application Code Hub
-
Filter Visible Examples (MCX + Sensors)
Go to the filter section next to the Search bar and select two filters.
MCX in the Device Families Section and Sensor in the Categories section of the filters. -
Search for Keywords in Examples
Search for the keyword 'heart rate'.
Select the demo "frdm mcxa153 freemaster heart rate". -
Read Overview of Heart Rate Demo
The Application Code Hub provides a consistent Readme Overview for every project. The FreeMASTER Heart Rate demo overview is previewed after clicking on the application card.
Scroll through the readme to become familiar with the available contents like required hardware, software and setup instructions. -
Select Destination for Project
The wizard automatically provides a prompt to browse to a desired destination folder. Choose the Folder C:\VS-Code-Projects\Heart-Rate. -
Import Project into Workspace
Select Import Project(s) after entering the desired location.
If a valid project is not available, the wizard only displays Import Repository, to allow a code repo, without a project, to be added to workspace. -
Select Detected Project(s)
The import wizard will scan the example repo and list valid projects that were discovered. This allows the user to select only the projects they want created. Select the mcuxpresso project listed at the top of the VS Code window below the Workspace Search bar.
-
Choose a Toolchain
The last selection is to identify the Compiler toolchain to be used for the project. GCC will be used for this project.
Select Arm GNU Toolchain 12.3.Rel1 (Or latest version available from MCUXpresso Installer prework) The scan may locate Compilers associated with MCUXPresso IDE. Verify the path and version between listed compilers.
At this time the wizard completes importing the project into the workspace.
A Successful Conversion notification is displayed at the bottom of the screen. It is important to recognize that the selected Heart Rate example is a working project within the MCUXpresso IDE (Eclipse based). The VS Code extension has a ability to convert an existing project with a few requirements.
The MCUXpresso for VS Code extension includes a PROJECTS section to help users access useful project information.
A user can review and modify project information with the following steps.
-
Review Project Details
Project details are shown in the Dropdown menu of the Projects Section in the MCUXpresso Extension Navigation Pane-
Repository Information: Verify the necesary SDK is associated with converted project.
NOTE: Step 2 below details how this can be corrected. -
MCU: Understand the targeted device and board.
-
Memory: View quick memory map of project.
-
Build Configurations: Select build configuration from available list (i.e. Debug or Release).
-
-
Associate the Required MCUXpresso SDK
Sometimes, Projects imported/converted from the Application Code Hub do not automatically have a valid SDK associated to them. This can be caused by the required SDK not being installed and imported into the workspace.The prework for this lab installed the expected FRDM-MCXA153 SDK. The import wizard should associate the information from the project with the available SDK.
If Project information is blank (i.e. Repository Information), you must manually associate an SDK with a project.The Following steps will assign the FRDM-MCXA153 SDK to the project:
-
Right Click on the Project to fix.
-
In the Drop-down menu, Select Configure -> Associate Repository
-
Select SDK-FRDM-MCXA153 from a list of availble SDK repos listed at the top of VS Code window below search bar.
Now the correct information should be displayed for the project.
NOTE: If a valid SDK is not assigned, a project will fail to build with an Error message noting that a CMAKE build configuration is not located.
-
-
Working with Source Files
The MCUXpresso extension PROJECTS view does not include the source files. Visual Studio Code leverages a dedicated Explorer view to work with files associated with projects found in the workspace.
To view the project files:- Click on the Explorer Icon at the top of the VS Code left navigation pane. (Highlighted in image below)
- Click on mcuxpresso and you will find the Source files like main.cpp etc in the Dropdown
The MCXA153 FreeMASTER Heart Rate project needs to build the application image. After the code builds without any errors, the application can be run on the FRDM board.
The following steps require that you return to the MCUXpresso perspective by clicking the MCUXpresso for VS Code X icon in the left navigation pane.
-
Build the project by clicking the Build Selected icon.
After a successful build, the Terminal console displays the memory usage (or compiler errors if any).
To use the Serial Monitor integrated into VS Code:
-
Connect the USB-C cable to J15 to power the FRDM board. The onboard debugger provides a USB-UART bridge to interface with the Serial monitor.
-
Click on the SERIAL MONITOR found as a tab in the Terminal window at the Bottom of VS Code Window.
NOTE: The default COM settings are valid for NXP eval boards: "115200, None..." -
Click Start Monitoring to connect the monitor to the FRDM board’s auto-detected COM port.
It can be disconnected by clicking Stop Monitoring after debug.
This section uses the on-board debugger to connect to the MCU, and program the flash. LinkServer from NXP manages the GDB server for communicating with the NXP MCULink on-board debug probe. It includes support for flash programming.
-
Click the play icon to Debug the application:
The application is flashed to the FRDM board and VS Code switches to the Debug perspective.
Return to the SERIAL MONITOR tab under the Terminals. It switches to the OUTPUT terminal when a Debug session is started. -
The execution will be paused.
Click Continue/Play icon to continue execution.
The application will advance to the start of main().
Click Continue/Play icon a 2nd time for the Heart Rate application to launch inside main().
-
View Heart Rate Values in Serial Terminal The Heart Rate application using the serial port to display information.
- The following should be displayed in the SERIAL MONITOR tab after main() starts:
sensor_init init complete
- Place a finger on the sensor near the Heart silkscreened on Heart Rate 4 click board.
The following should be displayed in the SERIAL MONITOR tab after a finger is placed on the sensor:
g_sample_count:0, hr:0 ecg:104, blood:0: g_sample_count:0, hr:0 ecg:106, blood:0: g_sample_count:0, hr:0 ecg:127, blood:0:
- A heart rate value will be calculated and displayed after g_sample_count reaches 250 valid samples:
g_sample_count:249, hr:0 ecg:104, blood:81: g_sample_count:250, hr:72 ecg:86, blood:81: g_sample_count:251, hr:72 ecg:68, blood:81:
FreeMASTER is a standalone application provided by NXP to help developers visualize, monitor and manipulate data available from their projects.
The Heart Rate example includes a /freemaster folder that helps users get started using the tool.
The settings in the Application Code Hub were established for an MCUXpresso IDE based project. There are a few changes that need to be made after the project is converted to a VS Code project.
The following steps will properly configure FreeMASTER to work with the Heart Rate example project:
-
Launch FreeMASTER Application
There are two options for launching FreeMASTER.-
Click on the heart_rate.pmpx using File Explorer. The FreeMASTER application should be associated with .pmpx file extensions. This will also automatically load the included project settings. (Folder location may vary based on choices made in Section 2)
-
Launch FreeMASTER by searching Windows Applications.
This will not load project settings. You will be required to Open Project using the FreeMaster menu as shown. Open the .pmpx project file located in the location chosen in Section 2)
-
-
Verify Project Options
FreeMASTER has a few key settings to verify once a project is opened. A user should verify they are correctly set for the type of Debug Probe and location of the project output files.-
Click Project -> Options from the menu bar.
- Verify that the correct method is set for communicating with the board. The on-board Debug Probe for the FRDM-MCXA153 is by default shipped with NXP CMSIS-DAP firmware.
Select FreeMASTER CMSIS-DAP Communication Plug-in found under the Comm tab, for Plug-in module:
NOTE: SEGGER and PEMicro options are available for alternate debug probes or on-board firmware)
- Verify that the correct Default symbol file is targeted for the VS Code project. The symbol file in VS Code projects is output under an /armgcc folder.
Select the /armgcc folder within VS Code project MAP Files tab
The window will autodetect the Binary ELF File, and display this under File format:.
-
Click Project -> Options from the menu bar.
-
Visualize Data From Heart Rate Project
The NXP software team has included a default visualization for the Heart Rate project. The demonstration showcases the different styles for project data to be shown.
The following visualization settings are preset for the Heart Rate project:
-
Welcome HTML Page: The HTML Pages (Under Options) points to welcome.html file. This provides structured web view for displaying elements. Beyond scope of this lab, but .html file can be reviewed to see how target values/charts are referenced in html.
-
Oscilloscope Visual: View plots the values of a project variable. The plot axis are configured for scale and color. Heart Rate, SPO2 and ECG are configured.
-
Variable Watch Table: After variables are configured to be tracked, they can be added to this table view.
Click GO icon on the menu bar to initiate the project data visualization! The following points are highlighted for the FreeMASTER output.- Clicking on the elements listed under the Project Tree changes the view to the specific Oscilloscope Visual.
- View the captured values for the variables in a Table view
- Visualization of data organized based on the layout defined in the Welcome.html
-
Customize FreeMASTER for Application Variable
The FreeMASTER tool makes it easy for users to add new values to the visualization. The following steps will add the ability to see the value of the IR detected by the shield sensor. The on-board IR sensor detects the amount of IR light reflected back into the small opening of the black casing. The reflection works best when object is within 1" of the sensor. This is NOT a long range IR detector.-
Select new variable from List of all valid symbol files, found under Project->Options
Click on View to open a list of available variables:
-
Add selected Variable to the FreeMASTER project
Use values located in the symbol file to configure the parameters for a New "IR Value" variable in the project.
Click Project->Variables from the menu bar to add a New variable
NOTE: You can also us VS Code Explorer to search and review the variable details in the project source files.
-
Add Oscilloscope Visual for new Variable The New "IR Value" variable can be displayed by adding an Oscilloscope to the Project Tree
Under the Variables tab, add IR Value to the Graph Block
-
Restart the capture of application data with new Visualization
Click Go again to have the new variable data populated in the new Visualization.
-
You have now succesfully completed the MCXA FreeMASTER Heart Rate Lab.
Return to Getting Started with MCX using Application Code Hub
Use this GitHub Issues section to report ambiguities or problems encountered in this documentation. For MCUXpresso for Visual Studio Code extension issues, feedback or search for solutions and ideas please follow Community page.
Table of contents
Dependency Installation
General
Software Repositories
Project Management
Flash and Debug
Reference Guides
- Getting Started with MIMXRT1060-EVK
- Training Zephyr Getting Started
- TrustZone Examples on LPC55S6x and MCUXpresso SDK
- Multicore Examples on LPC55S6x and MCUXpresso SDK
- SDRAM Examples on RT1060 and MCUXpresso SDK
- Getting Started with MCX using Application Code Hub
- AN14120: Debugging Cortex-M on i.MX 8M, i.MX 8ULP, and i.MX 93
Troubleshooting
Useful links