About ESP32

ESP32 is a series of low-cost, low-power SoC microcontrollers with integrated WiFi and Bluetooth capabilities, created and developed by Espressif. Apart from M5Stack, many ESP32-based modules and development boards are available.

Command-line toolset distributed with the official development framework (ESP-IDF)

You should install Arduino Core for ESP32 and M5Stack Library as separate components

The reset of this section describes how to set up a cross-development environment for M5Stack in which you can upload your programs via USB cable.
Other options, for example, setting up cloud-based development environments or methods for uploading programs via WiFi are skipped for now.

First, you need to install USB-UARD driver

Then, you can choose either of the following:

Arduino IDE

PlatformIO

ESP-IDF

Installing USB-UART Driver

M5Stack has a Silicon Labs CP2014 USB-UART adapter as the communication interface to the host PC.
Download an appropriate device driver for your PC from the following link and follow the instructions along with the driver.

If successfully installed, you can find the following USB-serial port when you connect M5Stack to your PC via a USB cable.

Mac: /dev/cu.SLAB_USBtoUART

Linux: /dev/ttyUSB0

You can easily check using shell command ls /dev/cu.* or ls /dev/tty*.

Notes on Cabling

If you cannot find the above port when you connect your PC to the M5Stack device, try to change the orientation of the USB-C plug connected to the device.
USB-C connectors are usually known to be reversible (no orientation).
However, the wiring of the USB-C connector of M5Stack body may be bit weird and have orientation.

Another possible trouble about cabling may occur when you are using a USB-C to USB-C cable. If your PC has only USB-C ports (like recent MacBook and MacBook Pro), you would like to connect to M5Stack using such cables.
In my experience, a few instances of M5Stack Core have a connection trouble with some USB-C to USB-C cables. In this case, reversing the connector orientation does not help. When you come across such trouble with your cable, it is better to give up to use the cable and use USB-C to USB-A adapter and the USB-A to USB-C cable included in the box of M5Stack Core.

Setting Up Arduino IDE

Installation

Download an appropriated Arduino IDE application from the following link and install it in your PC.

https://www.arduino.cc/en/Main/Software

Setting up for M5Stack

Method 1

You can easily install the required toolchain, framework and libraries using the board manager and library manager of Arduino IDE.

In the Preference window of Arduino IDE, add the following URL to “Additional Boards Manager URLs”.

https://dl.espressif.com/dl/package_esp32_index.json

Invoke Board Manager from Tools menu.
Type ESP32 into “Filter your search …” field and then select “esp32 by Espressif Systems” to install the framework and toolchain.