Skip to content

Firmware engineering review for ZT706S and ZT703S - #231

Closed
nbritton wants to merge 8 commits into
bve:mainfrom
nbritton:firmware/zt706s-engineering-review
Closed

nbritton wants to merge 8 commits into
bve:mainfrom
nbritton:firmware/zt706s-engineering-review

Conversation

@nbritton

@nbritton nbritton commented Nov 30, 2026 •

Copy link
Copy Markdown

Correction and upstream status

The maintainer closed this PR. Its original proposal changed the compiler mode and the contributor guide to C++23, contrary to the project's C++17 requirement. The corrected fork branch restores the guide, compiles OpenOSC code as C++17 and removes the C++20-only std::midpoint dependency. The original PR also bundled several changes. The wiki calls for an issue to agree on larger changes in advance and one focused change per PR. Contributing wiki

Upstream incorporated the scope cache/FFT and timer changes separately. The measurements and local tests below cover the corrected fork branch against its original v0.22.10 baseline (3a500ab). The ZT706S application saves 15,088 bytes of flash, with 79,524 bytes of reported static RAM. Upstream scope commit · Upstream timer commit · Corrected engineering review

Area Changes and evidence
Build and CI Use C++17 for STM32, host tests, UI screen tests, and project-owned companion code. ESP-IDF uses its SDK defaults for framework code. The STM32 keeps size optimization and LTO, with exceptions, RTTI, and thread-safe statics disabled. The ZT706S native environment covers DMM packets, ranges, and update packages.
Scope and FFT Remove the initialized flash copy of the 15,416-byte column cache. Fix an out-of-bounds intermediate iterator formed while selecting the Blackman FFT peak.
DMM trends Use 64-bit time slots, map span changes with integer arithmetic, and resolve the visible ring window once for both redraw passes. Regression tests cover rollover, expiry, HOLD marks, and span changes.
Timer planning Consider the maximum reload at the prescaler boundary and stop searching redundant divisor pairs. Check representative rates against a full prescaler search. A host benchmark of 300 requests at a 200 MHz timer clock fell from a median of 2.7816 s to 0.0187 s with the same register checksum of 12,620,761 (GCC 13.3, -Os, three runs).
Memory allocation Enforce the application’s SRAM4 limit and recovery’s reserved 96 KiB stack boundary in the newlib heap. An oversized request returns ENOMEM and preserves the current break.
Storage and updates Serve reads within a dirty NOR block from RAM. Skip the preliminary read for a full 4 KiB host overwrite. Compute the additional streaming image CRC only for bundled updates.
ESP32-C3 file transfer Wake the HTTP worker on a UART reply, shutdown, or timeout. Removing its 10 ms polling interval costs 80 bytes of static RAM. Battery current still needs a device measurement.

Linked footprint in bytes

Image Flash before → after Static RAM before → after
ZT706S application 1,348,480 → 1,333,392 79,524 → 79,524
ZT703S application 1,360,704 → 1,345,672 79,124 → 79,124
Each STM32 recovery 85,536 → 85,640 9,100 → 9,096
ESP32-C3 companion 1,251,350 → 1,251,404 51,212 → 51,292
ESP32-C3 web recovery 774,738 → 774,738 30,172 → 30,172

The STM32 RAM column covers ordinary data and BSS. On the ZT706S, the map leaves 96 bytes free in AXI SRAM, 1,856 bytes for the bounded C heap in SRAM4, and 50,264 bytes between BSS and the application stack top. The AHB record bank occupies its full 128 KiB. Live stack depth needs measurement on the handheld.

Testing

  • Built all four STM32 targets and both public ESP32-C3 targets with the release packaging script. The STM32 linker emitted the existing serial-LTO warning. All seven packaged assets passed SHA-256 verification.
  • All 131 PlatformIO native test cases and 39 Python tests passed. Board configuration, translations, and font coverage checks passed.
  • Screen tests passed under AddressSanitizer, LeakSanitizer, and UndefinedBehaviorSanitizer in English, Chinese, Russian, and Spanish. The suite reported zero clipped labels, shortened texts, or critical overflows.
  • Ran Cppcheck 2.22 across project and vendor sources and with target compilation databases. Additional local host harnesses exercised NOR flush failures and retry, stale mailbox replies and shutdown, and heap growth and shrinkage at both boundaries.
  • ZT703S hardware validation.
  • ZT706S hardware validation.

The two hardware checklist entries refer to the full corrected branch. A contributor separately tested selected commits on a ZT703S, including scope drawing and Blackman FFT readout, generator output, DMM span changes with flat readings, and valid and corrupted update uploads. Their DMM checks used a local C++17 midpoint replacement. USB close/reopen behavior, high-frequency acquisition, NOR power loss, ZT706S operation, and battery current remain outstanding. ZT703S scope report · ZT703S follow-up · USB issue #177 · Acquisition issue #190

Reproduce the automated checks

With the project's pinned PlatformIO and packaging dependencies installed, run from the repository root.

python3 scripts/generate_board_config.py --check
python3 scripts/i18n.py check
python3 scripts/build_fonts.py --check
python3 -m unittest discover -s scripts/tests
pio test -e native -e native_zt706s -e native_ui
python3 scripts/test_ui_screens.py
python3 scripts/build_firmware.py
(cd "build/releases/v$(cat VERSION)/assets" && sha256sum --check ../SHA256SUMS)

Checklist

  • The changes preserve the factory block at 0x08000000–0x0801FFFF.
  • The diff is confined to project-owned files. Vendor source trees match the base commit.
  • Restored the original C++17 contribution rule and updated the host test command. Installation follows the existing README.

@fletto2

fletto2 commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Hardware report for one commit of this PR, 9f8f1a1 ("Fix the Blackman FFT iterator and remove the scope cache flash copy"), on a ZT703S. The other seven commits (C++23, DMM trends, timer planning, heap bound, NOR/update, ESP32 mailbox) were not tested.

I applied 9f8f1a1 on top of a 0.22.10-based build (3a500ab plus some fork changes that don't touch these files). The code in column_cache.hpp, column_cache.cpp and spectrum_peak.cpp is identical to this PR; only one comment line in column_cache.hpp is worded differently.

  • Size: .data went from 16,884 to 1,464 bytes and the .OSC shrank by 15,388 bytes. I confirmed the cause: the only non-zero bytes in the old .data copy of applicationColumns()::columns were Viewport::gridRemainder = -1 (bytes 46-47).
  • Boot and drawing: the image installs with scripts/scpi_flash.py and boots. Y-T with both channels (the cached path) draws normally at 1 ms/div and 100 ms/div on a 1 kHz square from the generator.
  • Measurements and USB: the 1 kHz square reads a 1.000 ms period and 3.08 V amplitude, with no SCPI errors. 1200/1200 USBTMC abandon-and-clear cycles passed.
  • FFT (Blackman window, the case the iterator fix touches): the generator's 1 kHz signal gives a Pk readout of 1 kHz. WAV:SPEC? reports BLAC with a peak at 1000.01 Hz, and 100 repeated reads had no errors.
  • Host tests: native, native_ui and scripts/test_ui_screens.py all pass.

@fletto2

fletto2 commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Follow-up: hardware and host checks of f584707, d7d0962, 4a6b9e6 and a146739 on a ZT703S. I cherry-picked them with 9f8f1a1 onto 3a500ab, without ef992f5 (C++23).

Build: f584707 does not build without ef992f5, because std::midpoint is C++20. For these tests I replaced it with min + (max - min) / 2. The other commits build on their own.

f584707 (DMM trends)

  • Host: I ran the old and new History on the same random input (8 seeds, 200k steps each, with pushes, span changes, HOLD marks and gaps). The column() and markColumn() output is identical.
  • The fractional-microsecond case never occurs with Columns = 240 and the current spans. Old and new span mapping agree for every span pair over 200k slots.
  • 32-bit slots wrap only after about 5.7 years at the 10 s span.
  • Device: stepping Up/Down through all 8 spans and past both ends works, and the curve is remapped correctly. Only flat 0 V readings were used.

d7d0962 (timer planning)

  • Host: old vs new TimerPlan::calculate over about 1.5M inputs:
    • the generator's clocks and minimums: 200 MHz/32, 280 MHz/28, 360 MHz/36, and 2;
    • rates just above 65536 * k;
    • random inputs.
  • Same registers everywhere except 6 cases with an equal divisor (prescaler and reload swapped). None better, none worse, no new failures. Time: old 3514 s, new 1.6 s.
  • The capped-reload case changes the result only with a minimum period near 65536, as in test_maximum_period_can_be_the_closest_rate. No caller does that.
  • Device: generator square from 1 Hz to 100 kHz (16 frequencies) measures within 0.01 % of the request, the same as without the commit. The six shapes fit with 0.5-1.6 codes RMS residual.

4a6b9e6 (heap bound)

  • _malloc_r is reached only from _svfiprintf_r / __ssputs_r (asprintf-style growth). Nothing in the tree uses that, so the bound is never hit.

a146739 (NOR / update CRC)

  • The new readBytes branch uses the same cacheValid_ && dirty_ / scratch_ data as the existing overlay.
  • Device: I uploaded images over MMEM:UPL. END? re-reads the file through the block cache and runs ImageCheck:
    • format 1 (1,127,000 B) and format 2 (1,583,849 B) images pass;
    • the same images with one byte flipped in the middle fail (-230).
  • Not tested: the host full-block write path. It is in Recovery's MSC only, and Recovery was not replaced.

@bve bve closed this Nov 30, 2026
@nbritton nbritton changed the title Reduce STM32 firmware footprint, fix measurement edge cases, and enable C++23 Firmware engineering review for ZT706S and ZT703S Nov 30, 2026
bve pushed a commit that referenced this pull request Nov 30, 2026
Exercise DMM packet decoding, range selection and update packages for ZT706S using the existing C++17 host build. Adapt the packet fixture and board configuration from PR #231.
@bve

bve commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Thanks for restoring C++17 and revising the proposal. I took two changes from the corrected branch into main after a second review.

  • 5103dea avoids unnecessary NOR reads and the unused extra CRC pass on legacy updates. The payload CRC, bundled image CRC, font CRC, and NOR read-back verification remain in place.
  • fdb7d1e adds native ZT706S coverage in CI for DMM packets, range selection, and update packages using the existing C++17 configuration.

The scope cache/Blackman FFT and timer fixes were already incorporated in 4b97403 and 1119159.

The remaining items need separate follow-ups.

  • DMM trend needs to be rebased onto the current history code. The branch predates DMM trend plot: Ω unit, break curve at OL, thicker line #239 and would lose the gaps for overload readings, including when changing the trend span.
  • Newlib heap limits need a device check. The current ZT703S application has zero free bytes in the proposed heap region. Boot and normal use should be checked with the new allocation limits.
  • ESP32-C3 file transfer needs device testing for successful transfers, UART timeouts, and shutdown during a pending request. Any latency or power claims should be backed by measurements on the module.
  • Compiler configuration and the engineering report remain outside these changes. The existing C++17 build is sufficient for the two patches, and the report's size figures describe the older v0.22.10 baseline.

The STM32 builds, host suites, storage checks, and update validation passed locally. The new aligned full-block write path was exercised in the host NOR model. A device check through Recovery USB mass storage is still outstanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants