Open-source Zephyr RTOS firmware for the TYT MD-UV390 PLUS 10W GPS dual-band DMR handheld radio, built on an STM32F405VGT6 (ARM Cortex-M4, 168 MHz rated / 72 MHz configured, 192 KB SRAM, 1 MB Flash). PRs and issue reports welcome.
Status
Early bring-up on real hardware.
| Peripheral | Interface | Driver | Hardware | Firmware | Notes |
|---|---|---|---|---|---|
| RF / DMR | |||||
| AT1846S transceiver driver | I2C3 | auctus,at1846s | 🟢 | 🟢 | FM RX (AT1846S → HR-C6000 → speaker) — end-to-end functional; DCS squelch stub pending |
| HR-C6000 baseband driver | SPI bitbang-IRQ | hongrui,hr-c6000 | 🟢 | 🟢 | FM RX audio path functional (see above) |
| PTT | GPIO keys (PE11/PE12) | gpio-keys | ⭐ | 🟡 | Wired to the UI's TX indicator only; no RF transmit yet |
| DMR TX / AMBE / synchronisation | — | — | — | 🔴 | |
| Display | |||||
| HX8353E display driver | MIPI DBI 8080 bitbang | himax,hx8353e | ⭐[^1] | 🟢 | LVGL UI — FM VFO, Settings (Radio/Display/Info tabs), quick-menu overlay |
| Backlight | PWM (TIM3_CH1/PC6) | st,stm32-pwm | ⭐ | 🟢 | Brightness, backlight-off level, screen timeout, screen invert — Settings-driven |
| Input | |||||
| Keypad matrix driver | GPIO (3 rows) | gpio-kbd-matrix-shared-bus | 🟢 | 🟢 | Keypad → LVGL navigation |
| Rotary encoder | GPIO quadrature | gpio-qdec | ⭐[^2] | 🟢 | Volume/menu-value adjustment |
| Volume knob | ADC1 ch0 (PA0) | st,stm32-adc | ⭐ | 🟢 | Hysteresis-gated reading, audio-taper display curve |
| Storage | |||||
| Codeplug flash | SPI1 (W25Q128) | jedec,spi-nor | ⭐ | 🟢 🟡 | Read/decode (src/model/codeplug.c), hardware-validatedWrite — call chain wired end-to-end, flash write stubbed ( -ENOTSUP) pending CPS protocol support |
| Voice-prompt flash | SPI2 (W25Q) | jedec,spi-nor | ⭐ | ⚪ | |
| Power | |||||
| Battery voltage | ADC1 ch1 (PA1) | st,stm32-adc | ⭐ | 🟢 | OCV curve, status-bar %/V display |
| DAC1 | PA4 | st,stm32-dac | ⭐ | ⚪ | CTCSS/tone generation |
| Connectivity | |||||
| USB CDC-ACM | USB OTG FS | zephyr,cdc-acm-uart | ⭐ | 🟢 | Non-blocking ring buffer, pre-DTR replay |
| GPS UART | USART1, 9600 baud | st,stm32-usart | ⭐ | 🔴 | Fix acquisition / NMEA parsing |
| System | |||||
| Watchdog | IWDG | st,stm32-watchdog | ⭐ | 🟢 | Feed loop, green-LED heartbeat |
| Green / Red LEDs | GPIO | gpio-leds | ⭐ | 🟢 🟡 | Green: 1 Hz heartbeat Red: available, no indicator assigned yet |
| RTC | LSE 32.768 kHz | st,stm32-rtc | ⭐ | 🟡 | |
| I2S3 audio | I2S3_ext for full-duplex RX | st,stm32-i2s | ⭐ | 🔴 | Streaming (mic capture, DMR TX/RX audio) |
| Beeper | GPIO (PC8) | st,stm32-gpio | 🟡[^3] | ⚪ | Tones |
| Microphone | PA13 power enable | st,stm32-gpio | 🟡[^4] | 🔴 | Capture (DMR TX audio input) |
[^1]: https://github.com/ndoo/dmrtastic/blob/HEAD/Zephyr #108055 — pending next release.
[^2]: https://github.com/ndoo/dmrtastic/blob/HEAD/Zephyr #108010 — pending next release.
[^3]: https://github.com/ndoo/dmrtastic/blob/HEAD/Toggled directly; no PWM/tone-capable DT config yet.
[^4]: https://github.com/ndoo/dmrtastic/blob/HEAD/Power-enable pin only; capture path (I2S3) not wired to this use.
Legend: ⭐ implemented with upstream driver 🟢 implemented with out-of-tree driver 🟡 scaffolded 🔴 planned ⚪ future
Build
pio run -e mduv390plus
The first run downloads the Zephyr framework package (~1 GB).
Architecture
The firmware follows a model/view/controller split:
- model/ — device/settings state and thin 1:1 driver wrappers (
battery.c,codeplug.c,radio_settings.c,radio_state.c,radio_debug.c). No UI or business logic;radio_state.candradio_debug.care the only files that callDEVICE_DT_GET(DT_NODELABEL(at1846s))(business-level and raw-register access respectively). - view/ — LVGL widget creation and paint from values handed to it (
theme.c,status_bar.c,view/screens/,view/overlays/). No direct hardware access;status_bar.candscreen_settings.ccallmodel/radio_state.cgetters directly, everything else goes through a controller. - controller/ — orchestration between model and view (debounce, value tables, "what happens when X changes"):
settings_controller.c(Settings menu item tables and callbacks, moved out ofapp.c) andfm_vfo_controller.c(debounced retune/rollback state machine, moved out ofscreen_fm_vfo.c). - console/ — a text Controller/View surface over USB CDC-ACM, parallel to the LVGL one rather than outside it:
console_debug.c(register-level debug commands, backed only bymodel/radio_debug.c) andconsole_view.c(user-facing commands, backed only by the controllers above).
app.c/app.h (screen manager: nav, frame stack, event queue) and app_input.c (input bridge) sit above this split as the app shell. main.c, display.c, and watchdog.c are platform/system level, outside the UI's MVC tree entirely.
Flash
Put the device into DFU mode before running the upload command: hold PTT + SK1 while powering on.
west flash is not supported — the TYT bootloader requires a proprietary unlock/XOR sequence handled by tools/flash_tyt_dfu.py.
pio run -e mduv390plus --target upload
User Interface
An LVGL UI runs over the shared keypad/LCD data bus, driven by Up/Down/Enter/Back (keypad matrix) and CW/CCW (rotary encoder):
- FM VFO — the default screen; functional receive display.
- Settings — a persistent
Radio/Display/Infotabview (src/view/screens/screen_settings.c), built once at boot and never destroyed. Squelch, bandwidth, VFO step, brightness, backlight-off level, screen timeout, screen invert, visual-volume, battery-unit, and all-LEDs toggles are live; items blocked on missing subsystems (GPS, RTC, contacts, DMR) show as N/A. Settings state is centralized insrc/model/radio_settings.c, seeded from the codeplug's nv-settings block where a field mapping exists. - Quick-menu overlay — SK1 long-press.
Two-axis navigation convention, used consistently across every tabview: Up/Down always move focus (tab cycling, then row selection within a tab); the encoder never moves focus and instead adjusts whatever's currently focused.
Console Commands
Interactive console over USB CDC-ACM (src/console/). Debug commands
(console_debug.c) poke registers directly for bring-up; view commands
(console_view.c) go through the same Controller/Model layer the LVGL UI
uses:
| Command | Layer | Purpose |
|---|---|---|
at r/w |
debug | Raw AT1846S register read/write |
hc r/w |
debug | Raw HR-C6000 register read/write |
rssi |
debug | Raw AT1846S 0x1B noise/signal read |
cp list |
debug | List known codeplug flash regions |
cp dump <addr> <len> |
debug | Raw codeplug flash hexdump |
cp region <name> [idx] |
debug | Typed decode of one codeplug region |
cp settings |
debug | On-flash nv-settings block + magic number |
cp info |
debug | JEDEC ID, device info, calibration sanity check |
rtc r/w |
debug | Read/set the hardware RTC date-time |
reboot |
debug | Warm-reset the MCU |
status |
view | Current VFO/frequency/RSSI/squelch |
settings list / settings set <radio|display> <label> up|down |
view | Read/adjust any Settings-screen row |
css tx|rx off|ctcss|dcs |
view | Set the shared CTCSS/DCS setting |
tools/radio_diag.py drives the at/hc/rssi commands from the host for automated register sweeps and gain/filter characterization.
Upstream Contributions
| Contribution | PR | Status | In-repo implementation |
|---|---|---|---|
| HX8353E display driver | zephyrproject-rtos/zephyr#108055 | Merged to main 2026-06-12, not yet in a tagged release |
Vendored copy in drivers/hx8353e/, synced to the merged content — will be removed once the pinned Zephyr version includes it |
mipi_dbi_bitbang: generalize LUT to N GPIO ports |
zephyrproject-rtos/zephyr#115161 | Open for review, opened 2026-08-02 | tools/patches/003-mipi-dbi-bitbang-multiport-lut.patch, applied to the pinned framework — will be dropped once the pinned Zephyr version includes it |
gpio_qdec: add invert-direction property |
zephyrproject-rtos/zephyr#108010 | Merged to main 2026-05-04, not yet in a tagged release |
invert-direction DT property not yet adopted — will be enabled once the pinned Zephyr version includes it |
Design Notes
HR-C6000 SPI framing (drivers/radio/hr_c6000/)
The SPI control bus protocol is a 3-byte transaction { page, reg, value }
with CS asserted across all three bytes. Bursts append more value bytes
after { page, reg } and the chip auto-increments reg.
SPI bit-bang timing (drivers/spi/spi_bitbang_irq/)
Bus speed is set entirely by GPIO toggle overhead; the frequency field of
spi_config is ignored. On a 72 MHz Cortex-M4 with the STM32 GPIO driver
this comes out to roughly 4 MHz per bit, well within the HR-C6000 SPI
maximum.
USB CDC-ACM console (src/console/)
console_transport.c owns the one physical UART (USB CDC-ACM) and is the
only file allowed to touch it or the USBD stack. The whole USB lifecycle
(descriptor registration, enumeration wait, DTR handshake) lives in its own
thread so a stalled host or a misbehaving USB stack can't block the radio
control loop, the watchdog feed, or the UI. TX is mutex-guarded
(console_transport_write()) so log output and interactive command output
can never interleave mid-line on the wire.
Logging over USB is non-blocking: console_log_backend.c's
cdc_log_out_func() only writes into a ring buffer (drop-oldest when
full); a dedicated drain thread flushes it through
console_transport_write(). If the host stops draining, only the drain
thread stalls — logs accumulate and the oldest are dropped, but everything
else keeps running. Pre-DTR, the drain thread parks on a 100 ms poll so
boot-time logs are buffered for replay once the host opens the port.
Interactive commands (console_dispatch.c) run on a separate thread reading
the same UART's RX side via an interrupt-fed ring buffer, dispatching each
line to a table of {name, help, handler} entries split across
console_debug.c (hardware-direct) and console_view.c (Controller/Model
only) — see Architecture above.
Shared keypad/LCD bus (drivers/kbd_matrix_shared_bus/, src/display.c)
The keypad matrix scan borrows the same 8 GPIOs as the LCD's lcd_mipi_dbi
data bus and hands them back before returning, so the scan must run on the
same thread as the LVGL display driver (see
include/drivers/input/kbd_matrix_shared_bus.h).
Within the scan itself, two STM32-specific quirks apply:
- Mode-transition glitch: switching a pin directly from whatever output state it's in to input mode can produce a brief spurious HIGH glitch. The driver forces all row pins to output-low uniformly first, lets them settle, then switches to input, rather than transitioning them individually.
- No pull resistor on the input transition: the scan uses
NOPULLwith an active-high scheme rather than an internal pull-up, because an internal pull-up would source current onto lines also wired to the LCD's data input pins — which this shared bus can't tolerate.
AT1846S I2C access (drivers/radio/at1846s/)
The chip is operated over I2C at 400 kHz. Each register is a 16-bit value addressed by an 8-bit register number; access is two separate bus transactions (the chip returns stale data on a repeated start). A small per-bank cache suppresses redundant writes when the requested value matches the last successful write to the same register/bank.
Bus recovery runs on every boot, to clear any SDA hold left by a transaction
interrupted in a prior boot. i2c_configure() is never called afterwards:
on STM32F4 I2C v1, the runtime reconfigure path leaves the event interrupt
disabled — a known silicon/driver errata.
Volume pot hysteresis (src/app_input.c)
Volume-pot handling operates on the pot's native calibrated ADC reading
(vol_axis_ch's in-min/in-max span) rather than a rescaled percent, so
the taper LUT and the hardware volume (src/app.c) each round
independently at their own point of use.
The STM32F405's ADC has no hardware oversampler (zephyr,oversampling
returns -ENOTSUP) and zephyr,acquisition-time is already maxed at 480
ticks, so hysteresis is handled at the application layer instead: a new
value is reported only once it moves at least a gate's width — 1% of the
calibrated span, so it tracks in-min/in-max if retuned — from the last
one applied. analog-axis's own in-deadzone doesn't help here; it's a
center deadzone for joystick-style inputs, not a slider's full range.
The noise this fixes (CDC log capture showed oscillation between adjacent steps with the pot held still) occurs near the physical maximum, where the audio-taper reverse-mapping LUT is steepest. Near either extreme, a step moving toward it bypasses the gate so the ends of the range stay reachable; a step away from an extreme still needs the full gate, so it doesn't drift back on noise alone.
Display init failure (src/display.c)
LVGL's Zephyr auto-init skips registering a display whose underlying device
failed device_is_ready() (e.g. the HX8353E's init returning an error) —
lv_display_get_default() then returns NULL instead of failing directly.
lv_theme_default_init() doesn't handle that and previously crashed the
system with an unhandled fault; the LVGL thread now checks for it and
returns early, so a display-init failure only loses the UI — the radio
keeps receiving independently (see src/main.c).
UI threading & frame lifecycle (src/app.c, src/app.h)
All LVGL object access is confined to the LVGL thread (the one that calls
app_tick() and lv_timer_handler()). External contexts post ui_action_t
events via app_post_action(); app_tick() drains them each iteration —
this is the only place actions cross from the outside world into LVGL.
Frames (FM VFO, Settings) are created once at app_init() and never
destroyed — navigation hides the current frame and shows another, not
create/destroy churn. SCREEN_BOOT is the one exception: a one-shot
transient torn down by app_switch_screen() the first time it's called.
The rotary encoder has no lv_group binding: it adjusts whatever's
focused directly via UI_ACTION_ENCODER_CW/CCW rather than moving focus
itself (see User Interface above for the full
navigation convention).
Volume taper curve (src/app.c)
Hardware volume has no taper correction — the pot's own physical taper
already applies one; the raw reading is linearly rescaled to the 0-100%
the driver API expects. Display percentage, however, is reverse-mapped
through an 11-point piecewise-linear LUT (checkpoints at 0/10, 1/10, ...,
10/10 of the pot's native span) so the displayed value reads as
perceptually linear. Which LUT applies is chosen at compile time by the
AT1846S node's volume-taper DT property.
The default "audio A" (log) taper models the industry-standard ~10-15% output at 50% rotation (this board measured ~14% on-hardware) as two linear segments meeting at that point, rather than a smooth analytic curve — matching how these pots are manufactured (two overlapping resistive tracks).
volume_display_pct() scales the raw-minus-min offset by 10 before
dividing by the span, so the checkpoint index and the in-segment fraction
both come out of one exact calculation without requiring the span itself
to be a multiple of 10 (it isn't: vol_axis_ch's calibrated span is 1936
counts). The final interpolated value is rounded (DIV_ROUND_CLOSEST)
rather than truncated, which used to bias every step down by up to just
under one point.
Settings tabview navigation (src/view/screens/screen_settings.c)
The Settings screen's two-level hierarchy (tabs, then rows within a tab)
requires explicit group-membership management: lv_tabview_set_active()
only scrolls the tab container into view, it doesn't hide inactive tabs'
content. An earlier single flat group (tab buttons and the active tab's
rows all navigable together) meant Up/Down's PREV/NEXT traversal could
wander into off-screen rows from whichever tab wasn't showing. The fix
keeps the two levels from ever sharing group membership: tab buttons are
group members only at the tab level, the act
