# Working with the example code

## Setting up a project for NXP Cup

Inside MCUXpresso, create a new project by going to "File", "New", and then "Project". A wizard will appear, in which you should select "New C/C++ Project" under "C/C++".  &#x20;

![](https://2412084329-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9GLtaxrQtBdBRsFIJB%2F-Lpgb7B-7QGgJ89ecYbN%2F-LpggBqrf93pjYxLXfWG%2F01_NewProject.PNG?alt=media\&token=4b209e0d-d868-40fe-beff-1ec7a2f52ed9)

The SDK wizard is shown now. Select the MK64FN1M0xxx12 in the tap "SDK MCUs". Then select the "frdmk64f" board under "Available boards." This board fits the best to the ARC Board. Now, press "Next >".

![](https://2412084329-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9GLtaxrQtBdBRsFIJB%2F-Lpgb7B-7QGgJ89ecYbN%2F-LpgfwL6ch4YUFLGYIul%2F02_NewProject_SDK.PNG?alt=media\&token=1bfda52c-c4f0-483c-9740-6da809b12ade)

You can use any name, but for clarity, we will call it "NXPCUP\_c++". As project type select "C++ Project". The other settings can stay that way. Now you can finish the project wizard.

![](https://2412084329-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9GLtaxrQtBdBRsFIJB%2F-Lpgb7B-7QGgJ89ecYbN%2F-LpgfzkKUDG3v-HBqccI%2F03_NewProject_project_type.PNG?alt=media\&token=bba5a83f-11e1-4529-8701-9dcd8edbf9d2)

## Including the example code

{% hint style="success" %}
You can download the example code [here](https://nxp.gitbook.io/nxp-cup/downloads-and-links).
{% endhint %}

First delete the main-file, "NXPCUP\_c++.cpp", from the "source" folder. You will copy a new main into the folder. Now you copy all folders and files from the example code to the "source" folder in the project. Your project tree should look like this:

![Project tree of the example code](https://2412084329-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9GLtaxrQtBdBRsFIJB%2F-Lpgjwuufl13Uycp_cwS%2F-LpglCebU0z2lLS-4tIK%2F05_Projcet%20tree.PNG?alt=media\&token=eee27ce8-aa7f-4eae-9250-430d8c8b769d)

## Writing your own code

The `nxpcup_ARC_c++` is your main-file. Here you can call your implemented functions.&#x20;

![Structure of the code](https://2412084329-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9GLtaxrQtBdBRsFIJB%2F-LrDfqsmRwEJj7zLt6-u%2F-LrDhYoJWnYQKvBF2Gee%2Fimage.png?alt=media\&token=5d82e917-72a7-4a08-9163-89608c68962e)

The software is based on a 3-layers model:

1. **Interface Layer**

   The lowest layer is the one which interfaces the hardware peripherals.
2. **Module Layer**

   The middle layer makes the peripherals work, using the interface layer. It controls the lighting luminosity, the acquisition of the image from the camera, the control of the motors through the HBridge, the control of the servomotor, the measure of the speed of each motor and the control of the wifi module.
3. **Manager Layer**

   You can write your algorithm here by using the given file structure in the Applications folder.

## Build, Flash, Run and Debug

Within the Quickstart Panel you can build and debug the project.

![](https://2412084329-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9GLtaxrQtBdBRsFIJB%2F-Lpgjwuufl13Uycp_cwS%2F-LpgqJPpaK9rAXs9Jg0t%2F06_1_Quick_start_panel.png?alt=media\&token=e6a60be9-685f-4556-a04b-070140e38982)

{% hint style="warning" %}
Flashing and debugging the Micro E board requires a **JLink Debugger**!&#x20;

Connect the JLink to the connector **J13** on the Micro E board.

The USB port cannot be used for programming!
{% endhint %}

Build the project first, then you can flash and run the project with the GUI Flash Tool. (see Picture below)

![](https://2412084329-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L9GLtaxrQtBdBRsFIJB%2F-Lpgjwuufl13Uycp_cwS%2F-Lpgm_Rx4gEg3Ry5IdzF%2F08_MCU_Toolbar_GUI.PNG?alt=media\&token=81a3402d-c6f1-4e5f-acb6-5d30f1f4c768)

For debugging use the "Debug" button from the Quickstart Panel.

## More support

Further documentation and videos are available on the NXP website.

{% embed url="<https://www.nxp.com/support/developer-resources/software-development-tools/mcuxpresso-software-and-tools/mcuxpresso-integrated-development-environment-ide:MCUXpresso-IDE?tab=Documentation_Tab>" %}

{% embed url="<https://www.nxp.com/support/developer-resources/software-development-tools/mcuxpresso-software-and-tools/mcuxpresso-integrated-development-environment-ide:MCUXpresso-IDE?tab=Design_Support_Tab>" %}
