> For the complete documentation index, see [llms.txt](https://nxp.gitbook.io/vmu-rt1176/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nxp.gitbook.io/vmu-rt1176/examples/testing-can3-in-px4.md).

# Testing CAN3 in PX4

CAN3 Port Bring-up and Testing in PX4-Autopilot

At this point time (11/11/2024) CAN3 is not enabled to use DronCAN or UAVCAN by default in PX4.\
The port itself is enabled and can be exercised using CANSEND and CANDUMP commands\
&#x20;\
This tutorial describes how to enable the CAN3 Port on the NXP-VMU-RT117x in PX4-Autopilot, and demonstrates the transmission of CAN Frames between two VMU-RT117x using the can-utils module.

## ITEMS REQUIRED

<table data-full-width="true"><thead><tr><th width="100" align="center">S.No.</th><th>Name</th><th width="100" align="center">Quantity</th></tr></thead><tbody><tr><td align="center">1</td><td><a href="https://github.com/NXPHoverGames/NXP-FMUMRT">NXP-VMU-RT117x</a></td><td align="center">2</td></tr><tr><td align="center">2</td><td><a href="https://nxp.gitbook.io/mr-b3rb/archive/whats-in-the-box-pre-production-version/witb-mr-b3rb-bmf#j-link-edu-mini-debugger">J-Link EDU MINI DEBUGGER</a></td><td align="center">2</td></tr><tr><td align="center">3</td><td><a href="https://holybro.com/products/pixhawk-debug-adapter">Pixhawk Debug Adaptor</a></td><td align="center">2</td></tr><tr><td align="center">4</td><td><a href="https://www.apple.com/shop/product/HN892ZM/A/mophie-usb-a-cable-with-usb-c-connector-1-m">USB-C (Male) to USB-A (Male) Cable</a> [Connects VMU-RT117x and Pixhawk Adaptor with the host]</td><td align="center">4</td></tr><tr><td align="center">5</td><td><a href="https://in.rsdelivers.com/product/rs-pro/rs-pro-usb-20-cable-male-usb-a-to-male-micro-usb-b/1828498">Micro-USB (Male) to USB-A (Male) Cable</a> [Connects J-Link EDU Mini Debugger with the host]</td><td align="center">2</td></tr><tr><td align="center">6</td><td><a href="https://baskaerospace.com.au/shop/cables/jst-gh-4-pin-twisted-can-cable/">4-Pin JST-GH to 4-Pin JST-GH (Twisted CAN Cable)</a> [Connects the CAN3 Ports of VMU-RT117x]</td><td align="center">1</td></tr><tr><td align="center">7</td><td><a href="https://www.pcboard.ca/jst-sh-10-pin-cable">JST SH 10-Pin Cable</a> [Connects VMU-RT117x and Pixhawk Debug Adaptor]</td><td align="center">2</td></tr><tr><td align="center">8</td><td><a href="https://www.adafruit.com/product/1675">10-Pin 2x5 Socket-Socket IDC (SWD) Ribbon Cable</a> [Connects J-Link and Pixhawk Adaptor]</td><td align="center">2</td></tr></tbody></table>

{% hint style="info" %}
Note: We require 6 USB-A (Female) ports on the host machine for this setup. You may utilize a USB-HUB (USB-A Male to USB-A Female) to get multiple ports on your host machine.
{% endhint %}

## HARDWARE SETUP

The high level overview here is that we want to be able to both program and  gain console access to the MR-VMU-RT1176 so we can issue commands. Note that there are other valid ways to get a console, such as through an attached Telemetry radio.  Programming may also use MCU-LINK-MR.

<figure><img src="https://2727163534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCjtagJvJqLjd2arsEF0L%2Fuploads%2FnWV5AwlIp7QtHrqZbtZq%2FIMG_0319.jpg?alt=media&amp;token=ab79aa4c-0875-4049-bd58-2cbe188121e5" alt=""><figcaption><p>Hardware Connections for Reference (Without USB Wires)</p></figcaption></figure>

<div><figure><img src="https://2727163534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCjtagJvJqLjd2arsEF0L%2Fuploads%2FBblm633faXNxDucHVsQK%2FIMG_0313.jpg?alt=media&amp;token=615a1cb8-48de-4412-8eb9-67e96ef8ef5d" alt=""><figcaption><p>CAN3: 4-Pin JST-GH to 4-Pin JST-GH (Twisted CAN Cable) Connection with the CAN3 Port on VMU-RT117x</p></figcaption></figure> <figure><img src="https://2727163534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCjtagJvJqLjd2arsEF0L%2Fuploads%2FXku0IQzg4HAD2BsOg1yf%2FIMG_0315.jpg?alt=media&amp;token=fa3d246b-f9b5-4544-8289-5c46d2e499b3" alt=""><figcaption><p>USB-C Connection with the CAN3 Port on VMU-RT117x</p></figcaption></figure> <figure><img src="https://2727163534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCjtagJvJqLjd2arsEF0L%2Fuploads%2FDm99gBKXqmtTePCxtaJd%2FIMG_0316.jpg?alt=media&amp;token=318e1543-f62f-42d0-bc44-306808f1a438" alt=""><figcaption><p>DEBUG: 10-Pin 2x5 Socket-Socket IDC (SWD) Ribbon Cable Connection with the Debug port on VMU-RT117x</p></figcaption></figure></div>

<figure><img src="https://2727163534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCjtagJvJqLjd2arsEF0L%2Fuploads%2FotWB9VWO4U3cOMqN8wz4%2Fblock_diagram.svg?alt=media&amp;token=4c0f47eb-a059-4017-8390-1883affb5689" alt=""><figcaption><p>Block Diagram for Hardware Connections (Complete)</p></figcaption></figure>

## SOFTWARE SETUP

### PX4-Autopilot SETUP

```
cd ~
git clone git@github.com:PX4/PX4-Autopilot.git
cd PX4-Autopilot
make px4_fmu-v6xrt menuconfig
```

Select the following options:

1. Device Drivers → CAN Driver Support
2. License Setup → Use components that have GPL/LGPL licenses
3. Application Configuration → CAN Utilities → SocketCAN cansend tool
4. Application Configuration → CAN Utilities → SocketCAN candump tool

{% hint style="warning" %}
In file "\~/PX4-Autopilot/platforms/nuttx/init/imxrt/rc.board\_arch\_defaults", add the line "param set-default -s UAVCAN\_ENABLE 1" after line number 6.
{% endhint %}

<pre><code>cd ~/PX4-Autopilot

<strong>make px4_fmu-v6xrt
</strong>make px4_fmu-v6xrt_bootloader
</code></pre>

<figure><img src="https://2727163534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCjtagJvJqLjd2arsEF0L%2Fuploads%2Fji4mZE903OV1U0JMzmWy%2FScreenshot%20from%202024-11-06%2012-28-58.png?alt=media&amp;token=090bbfb8-d6a8-4b55-83fa-e99050aea58a" alt="" width="563"><figcaption><p>Successful Build Output for px4_fmu-v6xrt</p></figcaption></figure>

<figure><img src="https://2727163534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCjtagJvJqLjd2arsEF0L%2Fuploads%2FMAHv8tXNrzf2QB0Vl56r%2FScreenshot%20from%202024-11-06%2012-31-02.png?alt=media&amp;token=21e70dcf-3871-414d-a76e-13f6170be40c" alt="" width="563"><figcaption><p>Successful Build Output for px4_fmu-v6xrt_bootloader</p></figcaption></figure>

### FLASH PX4-Autopilot on VMU

{% hint style="danger" %}
For simplicity, connect only one setup at a time with your host machine, i.e. only 1 VMU-RT117x + Pixhawk Debug Adaptor + J-Link EDU MINI.

Alternatively, you may connect both the setups simultaneously and select the appropriate J-Link when running JLinkExe command.

<img src="https://2727163534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCjtagJvJqLjd2arsEF0L%2Fuploads%2FHxf9RFARb4jNI0JcSWvh%2Fimage.png?alt=media&amp;token=97fbd1c5-ad0b-4328-893e-a75a8aa0aebf" alt="" data-size="original">
{% endhint %}

{% hint style="info" %}
Note: The following steps need to be run once for each of the two VMU-RT117x.
{% endhint %}

Open a new shell and perform the following steps for flashing PX4-Autopilot on VMU-RT117x.

{% code overflow="wrap" fullWidth="false" %}

```
cd ~/PX4-Autopilot
JLinkExe
connect
MIMXRT1176XXXA_M7
S
4000
loadbin boards/px4/fmu-v6xrt/extras/px4_fmu-v6xrt_bootloader.bin 0x30000000
loadbin build/px4_fmu-v6xrt_default/px4_fmu-v6xrt_default.bin 0x30020000
```

{% endcode %}

<div><figure><img src="https://2727163534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCjtagJvJqLjd2arsEF0L%2Fuploads%2F1AZQeiAUJ2n4WQUmEusi%2FScreenshot%20from%202024-11-06%2012-51-05.png?alt=media&amp;token=3dd9a4f0-e5cb-4412-baf6-a0771ed76841" alt=""><figcaption><p>Setting up J-Link for Flashing VMU-RT117x</p></figcaption></figure> <figure><img src="https://2727163534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCjtagJvJqLjd2arsEF0L%2Fuploads%2F7uD4e2K7d1blzZ3PnJoc%2FScreenshot%20from%202024-11-06%2012-51-24.png?alt=media&amp;token=13c5f4cd-7f48-4b74-8ad9-f2d23f845485" alt=""><figcaption><p>Successful output for Flashing VMU-RT117x</p></figcaption></figure></div>

## EXECUTION STEPS

Get the serial shell of the two VMU-RT117x on your host machine.

{% hint style="warning" %}
Note: Baudrate for the serial console is **57600**.
{% endhint %}

<figure><img src="https://2727163534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCjtagJvJqLjd2arsEF0L%2Fuploads%2Fea5ARnoNuzPxutL74GmP%2Fimage.png?alt=media&amp;token=c725b8a0-a5e6-4bc5-9bfa-a90a65f42ce3" alt=""><figcaption></figcaption></figure>

Execute `"`**`candump can2`**" on one shell and "**`cansend can2 123#1234567890`**" on the other.&#x20;

<figure><img src="https://2727163534-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCjtagJvJqLjd2arsEF0L%2Fuploads%2FEkK8faDV2iY3MPUI22mC%2Fimage.png?alt=media&amp;token=88b9657a-eb86-4c5b-a5eb-bcc0c3d5956c" alt=""><figcaption></figcaption></figure>
