M5Stack Tab5 Review – Part 2: Getting started with ESP32-P4 firmware development using the ESP-IDF Framework and Arduino IDE

In the first part of the review, we checked out the hardware of the M5Stack Tab5 ESP32-P4 IoT development kit and tried the demo firmware, whose user interface allows the user to quickly experiment with the camera, microphone, speaker, WiFi, power consumption, GPIOs, RS485, and more.

Since there’s no user application for the Tab5 at this stage, I decided to look into software development resources for the ESP32-P4 devkit in the second part of the review. I’ll first follow the instructions to build the demo firmware from source using the ESP-IDF framework, then analyze key aspects of the source and make some small modifications. After that, I’ll have a look at ESP32-P4 Arduino support via M5Unified and M5GFX library.

ESP-IDF 5.4.1 installation and ESP32-P4 Hello World program

The first step is to get the ESP-IDF 5.4.1 and configure ESP32-P4 following the instructions on the Espressif website, before testing it with a Hello World program.

Let’s check out the SDK first:


We can now install the tools for the ESP32-P4 target:


Now run the export.sh script to set the environment variables:


The script tells me that I could clean up some old ESP tools I had installed with the commands:


Let’s try if the ESP-IDF framework has been installed properly by building the Hello World application and running it on the Tab5. Note that this will wipe out the demo firmware.

But before that, we’ll connect the Tab5 to our host machine with a USB-C cable and longpress the reset button for about 2 seconds to enter download mode. This is what the kernel output on an Ubuntu 24.04 host machine looks like:


We can now build the Hello World demo with the following commands:


This will end with:


Let’s flash the Hello World firmware to the Tab5:


Output ends with something like:


Now run the following command…


… press the Power button on the M5Stack Tab5, and monitor the output:


We can see a “Hello world!” string in there, so everything is good!

Building the Tab5’s demo firmware

We are now ready to build the M5Tab5 User Demo firmware. Let’s get the code:


Now we can export the environment variables for the demo:


This is the output:


We’ll need to enter downloader mode again, and build and flash the firmware with a single command line:


It will take a few minutes and end with:


Let’s press the power button to check whether the user interface is back.

M5Stack Tab5 ESP32-P4 kit flash firmware

Awesome! It only took me about 45 minutes to get to that point, including the time I spent documenting my experience, so it was rather painless. I’m not used to that!

Modifying the Tab5 demo code

Let’s check the code for the main app:


It’s a C++ program that relies on the Mooncake multi-app management and scheduling framework designed for microcontrollers. Another dependency is the popular LVGL graphics library, and we can see assets/images are not typical PNG or JPG files, but C files generated by a tool compatible with LVGL, with tables representing the data. See logo_5.c file as an example:


We can check the larger images by filtering the width:


I could change some icons, but let’s go big by modifying the 1280×720 launcher_bg.c file. We can import a PNG file to the LVGL online converter to get a C file using the RGB565(A8) color format.

However, the file is larger (15.6MB) than the original, so it would be tough to fit in a 16MB flash althought there might be some compression. There are also some differences in the output, so instead I installed an offline converter: (Note: As I completed this review, I noticed a newer version of the converter that outputs a file that should work just fine).


We can check the utility run without error:


Now let’s convert our PNG image (CNX Software logo) into launcher_bg.c using RGB565 color format and RGB565 dithering:


The filesize is even smaller than the original:


We can now replace the file in the code tree, clean the code (because idf.py flash or idf.py build won’t detect the code changes), and flash it to the Tab5 again:


Press the power button to start the Tab5.

ESP32-P4 Updated LVGL Image

That part worked too.

If we want to look at the low-level software, we need to go to the hal/components directory.

M5Stack Demo Source HALWhen I first tested the Tab5 demo firmware, I noticed the camera’s frame rate was rather low in full-screen mode. Let’s try to decrease the camera resolution and see what happens. We can do this by opening hal_camera.cpp:


Two defines are used for the camera width and height. Let’s change that to 640 x 360 to keep the same aspect ratio and rebuild the code. Sadly, this does not work and only crops the camera input. I tried to change some other hardcoded values in the source code, but eventually I gave that part up.

I eventually ended up on the PPA (Pixel-Processing Accelerator) documentation on Espressif’s website, and several parameters can be changed. I decided to try rotating the image by 180° by changing PPA_SRM_ROTATION_ANGLE_0 to PPA_SRM_ROTATION_ANGLE_180:


It worked this time!

M5Stack Tab5 ESP32-P4 rotate camera

M5Stack Tab5 / ESP32-P4 Arduino support with M5StackGFX and M5StackUnified

While the Tab5 User Demo could serve as a starting point, developers would have to make themselves familiar with the Mooncake framework, besides learning about the ESP-IDF framework and especially new ESP32-P4-specific features. Some people may prefer using the Arduino IDE, and links to the M5StackUnified and M5StackGFX Arduino libraries were just added to the documentation, albeit without actual instructions on how to use those. Let’s see what we can do.

We still have a starting point with generic M5Stack Arduino instructions. So I installed and ran the latest version of Arduino (v2.3.6):


I added the URL for the M5Stack boards (https://static-cdn.m5stack.com/resource/arduino/package_m5stack_index.json) in Preferences:

M5Stack Arduino Boards File

I could install the latest version of M5stack boards file (2.1.4).

M5Stack 2.1.4 Arduino boards file

M5GFX v0.2.8 and M5Unified v0.2.7 were released just a few days ago, but could still be installed directly from the Arduino IDE.

M5GFX M5Unified Arduino Libraries

All good so far. There’s just a little problem: Tab5 does not show in the list of boards… So instead, I selected ESP32P4 Dev Module from the ESP32 3.2.0 boards file released by Espressif and prayed this would work. As a side note, when I used to be an embedded software engineer/project manager, I found out that prayer, love, and sleep were some of the powerful debugging techniques. I’m speaking from experience!

Arduino IDE ESP32P4 Dev Module

My first test was the M5GFX’s AnalogMeter. The code failed to build the first time:


It was because of a type mismatch, so I had to cast one of the parameters to int (line 168):


But after that, the build could complete.

M5Stack Tab5 Arduino AnalogMeter Build

Flashing the firmware did not work due to memory issues:


That’s when I realized I had forgotten to check the parameters, so I changed the flash size to 16MB, selected a 3MB app/9.9MB FATFS partition scheme, and enabled PSRAM (probably the most important here).

ESP32-P4 Arduino Flash Size PSRAM

After telling my Tab5 I love her so much, I tried again, and… success!

M5Stack Tab5 Analog Meter Arduino demo

Since the demo is an animation, I also shot a short video to showcase the result.

I also tried a more complex demo “AtomDisplay_Factory.ino”, but the build failed:


The way I understand it, the ESP32-P4 requires a new ADC driver for Arduino, and the old one is deprecated. This would require changing the code quite a bit, so I’ll skip that one.

I also tried one of the M5Unified’s samples: Displays.ino. I didn’t have to modify anything, and it built out of the box.

M5Unified ESP32P4 Dev Module Displays Arduino demo

After flashing the firmware, the demo could run normally. It will first show some text and then run an infinite loop showing squares and circles.

M5Stack Tab5 M5Unified Graphics ino demo

Conclusion

The M5Stack Tab5 is a cute, yet versatile USB or battery-powered ESP32-P4 IoT development platform with a 5-inch touchscreen display, a speaker, a microphone, a microSD card slot, GPIO headers, an RS485 connector, WiFi 6, Bluetooth, and 802.15.4 connectivity, power consumption monitoring, an IMU sensors, and more.

So, from the hardware point of view, it looks like a great development platform for the ESP32-P4. But software/firmware support is equally important, and I’ve demonstrated above that the Tab5 can be programmed with either the ESP-IDF framework or the Arduino IDE. However, everything is still fairly new, and for instance, the M5GFX and M5FUnified Arduino libraries were just released a few days ago. So there’s still some work to do, as Arduino sketches may need to be modified to work, especially since the M5Stack Tab5 board is not listed in the available boards even with the latest boards file, and I had to select a generic ESP32-P4 Dev Module for this to work.

Hardware documentation looks OK with pinout diagrams, although schematics (at least PDF) may be good to have. However, users are mostly on their own at this stage when it comes to software/firmware development. It may not be a major issue since the kit targets developers, and documentation from Espressif and Arduino can be used instead.

I’d like to thank M5Stack for sending the Tab5 ESP32-P4 development kit for review. They sell the Tab5 for $55 or $60 on AliExpress and its online store without or with a battery. It’s out of stock right now, but I understand it, a new batch is scheduled for June. It may not be a bad thing, as I’d expect the Tab5 to show up in the Arduino IDE, and most/all samples to work by then.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress. We also use affiliate links in articles to earn commissions if you make a purchase after clicking on those links.

Radxa Orion O6 Armv9 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
0 Comments
oldest
newest
Boardcon LGA3576 Rockchip RK3576 System-on-Module designed for AI and IoT applications