---
description: Steps taken to flash the CM4 board, boot it, and connect it to PX4
---

# RPi CM4 Flash Guide

{% hint style="warning" %}
### Please **Note:**

* If you are using PX4, you will need to use PX4 1.13.1 or newer for PX4 to recognize this baseboard.
* The fan does not indicate if the RPi CM4 is powered/running or not.
* The power module plugged into Power1/2 does not power the RPi part. You can use the additional USB-C Cable from the PM03D power module to the CM4 Slave USB-C port.
* The Micro-HDMI port is an output port.
* Some RPi CM4 might not have a Wifi device and therefore won’t connect automatically unless you plug it into a router or a compatible Wifi dongle into the CM4 Host ports.
{% endhint %}

{% hint style="info" %}
This Pixhawk RPi baseboard supports Raspberry Pi CM4 and CM5. The CM5 requires more power, and the USB-C port used for flashing also powers the Pi. If your computer doesn’t provide enough power, use a powered USB hub for reliable flashing operation.
{% endhint %}

### Flash EMMC <a href="#flash-emmc-2" id="flash-emmc-2"></a>

First, we need to have the CM4 up and running. We need to prepare the hardware for it first. Considering the fact that you have already mounted your CM4 onto the baseboard do the following to be able to flash any required image on RPi CM4:

1. Switch the Dip-Switch on Holybro Pixhawk 6X+CM4 base board (located on top of UART\&I2C port) to RPi
2. Connect the baseboard to your desktop computer USB-C CM4 Slave port used power & flash the RPi CM4. There may be a prompt on some systems like macOS to allow the connection. Please allow it! Otherwise, where to connect? 😀
3. You need to use usbboot:

#### Linux / Cygwin / WSL

Clone this repository on your Pi or other Linux machine. Make sure that the system date is set correctly, otherwise, Git may produce an error.

This git repository uses symlinks. For Windows builds clone the repository under Cygwin:

```
sudo apt install libusb-1.0-0-dev
git clone --depth=1 https://github.com/raspberrypi/usbboot,
cd usbboot
make
sudo ./rpiboot
```

Note: sudo isn't required if you have write permissions for the /dev/bus/usb device.

#### macOS

From a macOS machine, you can also run usbboot, just follow the same steps:

1. Clone the usbboot repository
2. Install libusb (brew install libusb)
3. Install pkg-config (brew install pkg-config)
4. (Optional) Export the PKG\_CONFIG\_PATH so that it includes the directory enclosing libusb-1.0.pc
5. Build using make
6. Run the binary

```
$ git clone --depth=1 https://github.com/raspberrypi/usbboot
$ cd usbboot
$ brew install libusb
$ brew install pkg-config
$ make
$ sudo ./rpiboot
```

If the build is unable to find the header file libusb.h then most likely the PKG\_CONFIG\_PATH is not set properly. This should be set via export PKG\_CONFIG\_PATH="$(brew --prefix libusb)/lib/pkgconfig".

If the build fails on an ARM-based Mac with a linker error such as ld: warning: ignoring file /usr/local/Cellar/libusb/1.0.26/lib/libusb-1.0.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86\_64 then you may need to build and install libusb-1.0 yourself:

```
$ wget https://github.com/libusb/libusb/releases/download/v1.0.26/libusb-1.0.26.tar.bz2
$ tar -xf libusb-1.0.26.tar.bz2
$ cd libusb-1.0.26
$ ./configure
$ make
$ make check
$ sudo make install
```

Running “make” again should now succeed!&#x20;

After running rpiboot the below screen from your terminal should say that you are good to go for flashing a new image onto your CM4 board.

<figure><img src="https://2367252986-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLIgtGDAvVGkCKGOJb1bR%2Fuploads%2F2Z6N0CTXq5Im7JIwyjSf%2Frpiboot-test.jpg?alt=media&#x26;token=daa27a82-164a-4f4c-864e-fe55190090cc" alt=""><figcaption><p>RPiboot sanity check</p></figcaption></figure>

Note: if there are any pop-ups after this stage to eject an unknown disk, simply ignore them.&#x20;

* You can now install your favorite Linux distro, e.g. Raspberry Pi OS 64bit, using The `rpi-imager`. Make sure to add wifi and ssh settings (hidden behind the gear/advanced symbol).

```
sudo apt install rpi-imager
rpi-imager
```

1. Once done, unmount the volumes, and power down the CM4 by unplugging the USB-C CM4 Slave.
2. Switch Dip-Switch back to EMMC.
3. Power on CM4 by providing power to the USB-C CM4 Slave port.
4. To check if it’s booting/working, either check HDMI output, or connect via ssh (if set up in rpi-imager, and wifi is available).

### Connect PX4 to CM4 via serial <a href="#connect-px4-to-cm4-via-serial-3" id="connect-px4-to-cm4-via-serial-3"></a>

Pixhawk 6X talks to CM4 using Telem2 (`/dev/ttyS4`).

1. To enable this MAVLink instance, set the params:\
   `- MAV_1_CONFIG: TELEM2`\
   `- MAV_1_MODE: Onboard`\
   `- SER_TEL2_BAUD`: `921600 8N1`
2. reboot the FMU
3. On the RPi side, you can connect it to Wifi using a router or a Wifi Dongle.
4. Enable serial port to FMU by using `raspi-config`: Go to `3 Interface Options`, then `I6 Serial Port`.\
   Choose\
   `- login shell accessible over serial → No`\
   `- serial port hardware enabled` → `Yes`\
   Finish, and reboot.\
   (This will add `enable_uart=1` to `/boot/config.txt`, and remove `console=serial0,115200` from `/boot/cmdline.txt`
5. Now MAVLink traffic should be available on `/dev/serial0` at a baud rate of 921600.

### Try out MAVSDK-Python <a href="#try-out-mavsdk-python-4" id="try-out-mavsdk-python-4"></a>

1. Make sure the CM4 is connected to the internet, e.g. using a wifi, or ethernet.
2. Install MAVSDK Python:

```
python3 -m pip install mavsdk
```

1. Copy an example from the [MAVSDK-Python examples](https://github.com/mavlink/MAVSDK-Python/tree/main/examples).
2. Change the `system_address="udp://:14540"` to `system_address="serial:///dev/serial0:921600"`
3. Try out the example. Permission for the serial port should already be available through the `dialout` group.

You can also use your own power supply to power the RPi CM4 baseboard.
