Skip to content

Instantly share code, notes, and snippets.

@Manawyrm
Created Apr 12, 2022
Embed
What would you like to do?
PHP script to accompany esp32_spirecovery.ino
<?php
require_once("vendor/autoload.php");
use lepiaf\SerialPort\SerialPort;
use lepiaf\SerialPort\Parser\SeparatorParser;
use lepiaf\SerialPort\Configure\TTYConfigure;
$bios = fopen("bios.bin", "r");
$configure = new TTYConfigure();
$configure->removeOption("9600");
$configure->setOption("115200");
$block = 0;
$serialPort = new SerialPort(new SeparatorParser(), $configure);
$serialPort->open("/dev/ttyUSB0");
while (true)
{
$data = $serialPort->read();
echo $data."\n";
if ($data === "W") {
echo "write block " . $block . "\n";
$block++;
$data = fread($bios, 4096);
if ($data === false)
{
echo "done!\n";
exit();
}
$serialPort->write($data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment