Serial bootloader client for ESP32-family chips, for Elixir and Nerves.
{:ok, esp} = Esp32.connect("/dev/ttyUSB0", baud_rate: 921_600)
:ok = Esp32.flash_file(esp, "firmware.bin", 0x10000)
:ok = Esp32.close(esp)
Summary
Functions
Closes the serial port.
Opens port, resets the chip into its bootloader, and prepares it for flashing.
Erases the whole flash chip. Requires the flasher stub; may take up to two minutes.
Finds the first serial port backed by an Espressif chip or a common USB-serial bridge.
Writes binary to flash at offset.
Reads path and writes it with flash/4.
Reads a 32-bit register.
Hard-resets the chip so it boots normally. Reconnect before sending further commands.
Writes a 32-bit register.
Functions
@spec close(Esp32.Device.t()) :: :ok
Closes the serial port.
@spec connect( String.t() | :auto, keyword() ) :: {:ok, Esp32.Device.t()} | {:error, term()}
Opens port, resets the chip into its bootloader, and prepares it for flashing.
port is a serial device name, or :auto to use find_port/0.
Options:
:baud_rate- speed used after connecting (default 115200):initial_baud_rate- speed used to connect and load the stub (default 115200):use_stub- load the flasher stub (default true):reset- reset the chip into the bootloader (default true):reset_pin,:boot_pin-Circuits.GPIOpins wired to EN and IO0; without them DTR/RTS are used:connect_attempts- reset and sync attempts (default 7)
The chosen reset strategy is kept on the device for reset/1.
@spec erase(Esp32.Device.t()) :: :ok | {:error, term()}
Erases the whole flash chip. Requires the flasher stub; may take up to two minutes.
@spec find_port() :: {:ok, String.t()} | {:error, :no_port_found}
Finds the first serial port backed by an Espressif chip or a common USB-serial bridge.
@spec flash(Esp32.Device.t(), binary(), non_neg_integer(), keyword()) :: :ok | {:error, term()}
Writes binary to flash at offset.
Options:
:flash_mode,:flash_freq,:flash_size- rewrite the header of a bootloader image, seeEsp32.Image.patch_header/3(default:keep);:flash_sizealso tells the loader the chip size, which the ROM loader otherwise assumes is 2 MB:verify- compare the flash MD5 afterwards (default true):reboot- hard-reset the chip into the application when done, seereset/1(default false)
Images built for a different chip are refused; other data is written as is.
@spec flash_file(Esp32.Device.t(), Path.t(), non_neg_integer(), keyword()) :: :ok | {:error, term()}
Reads path and writes it with flash/4.
@spec read_reg(Esp32.Device.t(), non_neg_integer()) :: {:ok, non_neg_integer()} | {:error, term()}
Reads a 32-bit register.
@spec reset(Esp32.Device.t()) :: :ok | {:error, term()}
Hard-resets the chip so it boots normally. Reconnect before sending further commands.
@spec write_reg(Esp32.Device.t(), non_neg_integer(), non_neg_integer()) :: :ok | {:error, term()}
Writes a 32-bit register.