Tutorial: Core 0 DMA Audio, ULP, Industrial Buses & Asymmetric OTA
Beyond displays and wireless radios, PylotOS exposes deterministic C drivers for full-duplex digital audio, ultra-low-power coprocessors, industrial fieldbuses, smart-home discovery, and anti-brick firmware updates.
1. Core 0 Full-Duplex DMA I2S Audio (hal.audio_*)
Supported across codec-equipped boards (ES8311 + MEMS mic on Cardputer ADV & T-Embed, NS4168 + PDM mic on Core2 & StickC Plus2, AW88298 + ES7210 on CoreS3), while keeping smooth-envelope hal.beep() compatibility everywhere:
import hal
# Open 16 kHz 16-bit PCM full-duplex stream on Core 0 DMA:
hal.audio_open(sample_rate=16000, channels=1, enable_rx=True, volume_pct=75)
# Non-blocking PCM playback:
hal.audio_write(pcm_bytes, timeout_ms=20)
# Zero-copy microphone capture into a pre-allocated buffer:
mic_buf = bytearray(640)
read_bytes = hal.audio_read_into(mic_buf, timeout_ms=20)
hal.audio_close()
2. Power Management (esp_pm) & ULP-RISC-V / LP-Core (hal.ulp_*)
Combine Phase 2B Dynamic Frequency Scaling + Automatic Tickless Light Sleep with Phase 4 ULP coprocessor shared RTC RAM (ESP32-S3 ULP-RISC-V and ESP32-C6 LP-Core, enabled via --enable-ulp):
import hal
# Enable DFS + automatic tickless light sleep between asyncio events:
hal.pm_configure(max_mhz=240, min_mhz=80, light_sleep=True)
# Load a compiled ULP binary and exchange 32-bit words via RTC slow memory:
info = hal.ulp_info()
if info["supported"]:
hal.ulp_write_shared(0, 500) # Threshold register for ULP sensor loop
hal.ulp_load(ulp_program_bytes)
hal.ulp_run(period_us=500_000, wake_deep_sleep=True)
wake_count = hal.ulp_read_shared(1)
3. Industrial CAN / TWAI (hal.can_*) & Modbus RTU/TCP (pylotos.modbus)
import hal
from pylotos import modbus
# Native ESP-IDF TWAI (CAN 2.0B) controller:
hal.can_init(tx_gpio=2, rx_gpio=1, bitrate_bps=500_000)
hal.can_send(0x120, b"\x01\x02\x03\x04")
rx_data = bytearray(8)
frame = hal.can_recv_into(rx_data, timeout_ms=10)
if frame is not None:
arb_id, dlc, is_ext = frame
# Modbus RTU (CRC-16) frame builder/parser (over UART RS-485):
rtu_req = modbus.build_rtu_frame(1, 0x03, modbus.build_read_holding_pdu(0x0010, 2))
# Async Modbus TCP (MBAP) client for industrial PLCs & energy meters:
plc = modbus.ModbusTcpClient("192.168.1.50", port=502, unit_id=1)
await plc.connect()
regs = await plc.read_holding_registers(start_addr=0, count=4)
await plc.close()
4. MQTT 3.1.1 + Home Assistant Auto-Discovery (pylotos.mqtt_ha)
Zero-dependency async MQTT client that inspects hal.describe() to auto-publish Home Assistant discovery entities (heap_free, uptime_s, battery_pct, wifi_rssi) and enforces pylotos.policy on inbound command topics:
from pylotos.mqtt_ha import MqttHaService
mqtt = MqttHaService(host="192.168.1.10", port=1883, username="iot", password="secret")
await mqtt.connect()
await mqtt.publish_discovery()
await mqtt.publish("pylotos/lab_node/custom", '{"co2": 612}')
5. Unified Hybrid Asymmetric Recovery-OTA (sys_ota & pylotos.ble_dfu)
All 30 boards use the asym-v1 partition layout: a maximized ota_0 OS partition paired with a permanent <= 736 KiB pure-C Recovery in ota_1, health-gated confirm_boot() after the 7-stage POST, boot_fails >= 3 Safe Mode, offline /sd/update.bin recovery, and secondary NimBLE BLE DFU (pylotos.ble_dfu):
import sys_ota
st = sys_ota.status()
print(st["ota_schema"], st["running_partition"], st["boot_confirmed"])
# Stage a verified HTTPS Pull OTA via the permanent ota_1 Recovery engine:
sys_ota.stage_pull(
url="https://github.com/PylotOS/pylotos/releases/latest/download/pylotos-m5stack_cardputer_adv-ota.bin",
sha256="<64-hex-sha256>",
sig="<optional-ecdsa-p256-hex>",
reboot=True,
)