I wanted to flash the firmware for the esp32-cam using UART, and ran into some troubles early on.
- enable serial:
sudo raspi-config-> interface options -> enable serial -> reboot - after rebooting, run
dmesg -t | grep serialinitial output: $ dmesg -t | grep serial
uart-pl011 fe201000.serial: there is not valid maps for state defaultuart-pl011 fe201000.serial: cts_event_workaround enabledfe201000.serial: ttyAMA1 at MMIO 0xfe201000 (irq = 39, base_baud = 0) is a PL011 rev3serial serial0: tty port ttyAMA1 registeredbcm2835-aux-uart fe215040.serial: there is not valid maps for state defaultfe215040.serial: ttyS0 at MMIO 0xfe215040 (irq = 40, base_baud = 62500000) is a 16550systemd[1]: Created slice system-serial\x2dgetty.slice - Slice /system/serial-getty.hci_uart_bcm serial0-0: supply vbat not found, using dummy regulatorhci_uart_bcm serial0-0: supply vddio not found, using dummy regulator
Here we can see two issues:
-
the
systemd[1]line is the Pi tryingg to launch agettyservice on this port, if we try to flash anything over serial port, the Pi will interpret the esp32's data as text commands and thegettyservice will spam the line with login prompts. to fix this we need to edit /boot/firmware/cmdline.txt and remove any code that looks like:console=serial0,115200orconsole=ttyAMA1,115200, leave the rest of the code, such asconsole-tty1 root=PARTUUID... -
that
hci_uart_bcmis trying to initialize on serial0, this was the bluetooth module trying initialize on the serial port and corrupting the data stream. edit /boot/firmware/config.txt. go to the bottom and belowenable_uart=1adddtoverlay=disable-bt
reboot and check again:
$ dmesg -t | grep serialuart-pl011 fe201000.serial: there is not valid maps for state defaultuart-pl011 fe201000.serial: cts_event_workaround enabledfe201000.serial: ttyAMA0 at MMIO 0xfe201000 (irq = 40, base_baud = 0) is a PL011 rev3$ ls -l /dev/serial0lrwxrwxrwx 1 root root 7 Dec 27 09:02 /dev/serial0 -> ttyAMA0
good! now lets try to flash again:
$ cd industrial-iot/
bill@raspberrypi:/industrial-iot $ . .venv/bin/activate
(.venv) bill@raspberrypi:/industrial-iot $ esptool -p /dev/serial0 --baud 115200 write-flash -z 0x10000 firmware.bin
esptool v5.1.0
Connected to ESP32 on /dev/serial0:
Chip type: ESP32-D0WDQ6 (revision v1.1)
Features: Wi-Fi, BT, Dual Core + LP Core, 240MHz, Vref calibration in eFuse, Coding Scheme None
Warning: Detected crystal freq 41.01 MHz is quite different to normalized freq 40 MHz. Unsupported crystal in use?
Crystal frequency: 40MHz
MAC: 08:f9:e0:ed:01:f4
Stub flasher running.
Configuring flash size... Flash will be erased from 0x00010000 to 0x00105fff... Compressed 1006448 bytes to 639088... Writing at 0x000de2b4 [=======================> ] 82.0% 524288/639088 bytes...
At this point, I attempted to install minicom and I got a sudo error. I rebooted the device and couldn't get ssh'd back in. I connected the pi to my tv to see the boot and got error messages about fixing garbage files. I popped the sdcard out and mounted it on my laptop and checked the cmdline.txt file:
console=tty1 root=PARTUUID=bdeb291b-02 rootfstype=ext4 fsck.repair=yes rootwait cfg80211.ieee80211_regdom=US
i appended fsck.mode=force to the end, saved the file, unmounted the disk, loaded it back into my pi and powered it on.