Setting up M5Stack Cardputer Emulator on Linux

Follow these steps to set up an M5Stack Cardputer emulator on Linux and test MicroPython code before deployment.

1. Install ESP-IDF and ESP32 Tools

  1. Install prerequisites:
    sudo apt update
    sudo apt install git wget flex bison gperf python3 python3-pip python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
  2. Get ESP-IDF:
    mkdir -p ~/esp
    cd ~/esp
    git clone --recursive https://github.com/espressif/esp-idf.git
  3. Set up the environment:
    cd ~/esp/esp-idf
    ./install.sh
    . ./export.sh

2. Install QEMU for ESP32

  1. Clone and build QEMU for ESP32:
    git clone https://github.com/espressif/qemu.git
    cd qemu
    ./configure --target-list=xtensa-softmmu
    make
    sudo make install

3. Install MicroPython

  1. Clone the MicroPython repository:
    git clone https://github.com/micropython/micropython.git
    cd micropython
    git submodule update --init
  2. Build MicroPython for ESP32:
    cd ports/esp32
    make submodules
    make
  3. Flash MicroPython to QEMU:
    qemu-system-xtensa -nographic -M esp32 -m 4M -drive file=build-GENERIC/firmware.bin,if=mtd,format=raw

4. Testing MicroPython Code

  1. Write a simple MicroPython script, e.g., main.py:
    print("Hello, M5Stack Cardputer!")
  2. Load and run the script on the emulator:
    qemu-system-xtensa -nographic -M esp32 -m 4M -drive file=build-GENERIC/firmware.bin,if=mtd,format=raw -s -S
  3. Use GDB to interact with the QEMU emulator:
    xtensa-esp32-elf-gdb -ex "target remote localhost:1234" -ex "symbol-file build-GENERIC/application.elf"
  4. In the GDB session, load your MicroPython script:
    monitor load "main.py"
    monitor start

5. Additional Configuration

For a more accurate emulation of the M5Stack Cardputer, you may need to configure specific peripherals and interfaces based on the hardware features listed in the provided documents.