How to Use Nerves on M5Stack Core MP135

[日本語版はこちら](https://qiita.com/GeekMasahiro/items/aa84c2e3e4d116d728be)

# Introduction

I have made Nerves work on M5Stack Core MP135.

The Core MP135 is an SBC (Single Board Computer) that runs Linux. Unlike the Raspberry Pi, it comes with a case, allowing it to be used as an embedded device right out of the box.

https://shop.m5stack.com/products/m5stack-coremp135-w-stm32mp135d

Various devices are available for purchase and use.

https://shop.m5stack.com/collections/m5-sensor

# Nerves Livebook (for beginners)

I have published a Nerves Livebook image that can be written to an SD card and used.

https://github.com/masahiro-999/nerves_livebook/releases

Write the `nerves_livebook_core_mp135.zip` to the SD card and boot.

From a PC connected to the LAN,
open https://nerves.local.
The password is `nerves`.

Now you can use Livebook.
Modules such as circit.i2c are already installed, so you can start experimenting with Livebook right away.

# Supplement
It is actually recommended to install `fwup` on your PC and use `nerves_livebook_core_mp135.fw` for writing, as it creates partitions according to the SD card size and takes only about 10 seconds to write, which is super fast.
On Windows, please run fwup from an administrator command prompt. Without proper permissions, it will say that the SD card is not available.

# Customizing Livebook

Nerves Livebook comes pre-installed with useful modules such as Circuits.GPIO, but if you want to add more, you need to build the firmware.
Here is how you can do it. Set up an environment where Elixir's `mix` can run and follow the steps below.

```bash
$ git clone https://github.com/masahiro-999/nerves_livebook
$ cd nerves_livebook
$ export MIX_TARGET=m5stack_core_mp135
(Add any additional modules)
$ mix deps.get
$ mix firmware
$ mix burn
```

# Creating a Nerves Project (Advanced)

The procedure is basically the same as using Nerves on devices like the Raspberry Pi.
The main difference is the modification to `mix.exs` and setting `MIX_TARGET=m5stack_core_mp135`.

```bash
$ mix nerves.new hello_nerves
$ cd hello_nerves
(Modify two places in mix.exs)
$ export MIX_TARGET=m5stack_core_mp135
$ mix deps.get
(Add any additional functionality)
$ mix firmware
$ mix burn
```

Changes to mix.exs:
```diff
     :osd32mp1,
     :x86_64,
     :grisp2,
-    :mangopi_mq_pro
+    :mangopi_mq_pro,
+    :m5stack_core_mp135
   ]
 
   def project do
@@ -71,7 +72,8 @@ defmodule HelloNerves.MixProject do
       {:nerves_system_osd32mp1, "~> 0.15", runtime: false, targets: :osd32mp1},
       {:nerves_system_x86_64, "~> 1.24", runtime: false, targets: :x86_64},
       {:nerves_system_grisp2, "~> 0.8", runtime: false, targets: :grisp2},
-      {:nerves_system_mangopi_mq_pro, "~> 0.6", runtime: false, targets: :mangopi_mq_pro}
+      {:nerves_system_mangopi_mq_pro, "~> 0.6", runtime: false, targets: :mangopi_mq_pro},
+      {:nerves_system_m5stack_core_mp135, "~> 0.0.7", runtime: false, targets: :m5stack_core_mp135}
     ]
   end
 
```

Insert the SD card and boot the Core MP135. The Nerves logo will be displayed on the LCD.

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/532235/19b11071-434f-5f5b-d838-717e50aeb4fe.png)

A monitor connected to the HDMI port and a keyboard connected via USB allow for console operations.
If LAN is connected, SSH is also possible. This part is similar to the Raspberry Pi.

# Request for Support

The M5Stack Core MP135 is a relatively new device, launched in 2024. While it may not be widely known yet, it offers unique features such as a built-in case and a wide range of sensors and devices that can be easily connected using standardized connectors, setting it apart from devices like the Raspberry Pi. As an entry-level IoT device, it opens up exciting new possibilities.

Currently, the Livebook for Core MP135 is maintained through a fork of the official repository. With more community involvement and users, I believe it has the potential to gain official support from the main repository.

If you resonate with this vision, please consider starring this repository on GitHub to show your support. The more backing I receive, the closer we get to achieving official support.

https://github.com/masahiro-999/nerves_livebook

References:
https://nerves-project.org/
https://github.com/nerves-livebook/nerves_livebook
https://qiita.com/torifukukaiou/items/91441a14dcf66472af39