Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

- name: Run host unit tests
run: |
pio test -e native
pio test -e native -e native_zt706s
pio test -e native_ui

- name: Check the main screens in every language
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Host unit tests for hardware-independent code (protocol decoders, DMM packets an
on your computer, without a device:

```sh
pio test -e native
pio test -e native -e native_zt706s -e native_ui
```

A host C++ compiler (GCC or Clang) is needed. `pio run` does not build the tests. To add a suite,
Expand All @@ -79,8 +79,8 @@ in `platformio.ini`.
3. Make sure `pio run` builds all four environments without new warnings.
4. Test on hardware when the change affects the device behaviour, and say which model you used.
If you could not test, say so.
5. Follow the style of the surrounding code: C++17, no exceptions, no RTTI and no heap
allocation outside LVGL.
5. Use the C++23 features supported by the pinned Arm GCC 12.3 toolchain. Keep exceptions and
RTTI disabled and limit heap allocation to LVGL.
6. Do not modify the code in `vendor/`, except to update a third-party component as a whole.
7. Do not add code that writes to the factory block (`0x08000000`–`0x0801FFFF`).

Expand Down
51 changes: 51 additions & 0 deletions docs/ENGINEERING_REVIEW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Firmware engineering review

Reviewed the public OpenOSC tree at `3a500ab` (version 0.22.10) on 2026-11-30. The ZT706S application is the primary target. Its generator uses a serial module, while the ZT703S has a DAC/PWM output. Both share the scope, much of the multimeter, the storage stack and the update formats. The measurements below compare a build of that commit with the reviewed changes, using the same pinned compilers and release flags.

## Coverage and upstream context

| Area | Review and verification |
| --- | --- |
| Acquisition, DSP, calibration, instrument control and generator | Examined capture and interrupt handoff, FFT peak selection, timer divider selection, board capabilities and use of DMA-visible memory. Built both board configurations. Checked timer planning against a full prescaler search. |
| DMM, protocol decode, presentation, settings and localization | Traced packet decoding through the model-specific range tables, history, column reductions and UI. Ran the native and screen suites. The added ZT706S environment exercises its own packet, range and package rules in CI. |
| Platform, startup, display and power | Reviewed clock setup, watchdog servicing, the main and recovery loops, volatile register access, linker sections and stack reservations. Compared linked images and memory banks. |
| Storage, logging, USB/SCPI and recovery | Followed cache ownership, writeback, image validation, resource and program CRCs, USB session reset and main-loop dispatch. Checked both recovery images and the packaged applications. |
| ESP32-C3 companion | Built the public application and web recovery with ESP-IDF. Examined file requests, UART replies, portal shutdown and update-slot handling. The optional panel variant requires a separate private bundle. |
| Build tools, configuration and dependencies | Reviewed PlatformIO, the release workflow, board generation, translations and packaging. Ran Cppcheck 2.22 over the project and vendor source trees, then with the ZT706S application, recovery and ESP32-C3 compilation databases. Generated fonts, SDK macros and linker symbols limit the standalone analyzer's coverage. Vendor review covered integration, compilation and static scanning. |

Upstream work on transient DMM readings changes which packets contribute to statistics. The history changes here concern storage and display of readings after acceptance. High-frequency acquisition remains an open hardware validation item. [DMM pull request 151](https://github.com/bve/OpenOSC/pull/151) · [Scope validation issue 190](https://github.com/bve/OpenOSC/issues/190)

## Corrections and tradeoffs

- **Scope cache.** The 15,416-byte column cache previously had an initialized flash copy because its empty viewport contained a nonzero field. An optional viewport expresses whether the cache has a key. The linker now places the entire cache in DTCM `.bss`. On the ZT706S its size is still 15,416 bytes.
- **FFT.** The Blackman window starts its peak search at bin three. The old expression formed a pointer three positions past the beginning of a two-element array before subtracting one. The revised expression forms the valid end iterator directly.
- **DMM trend.** The absolute slot number now follows the 64-bit instrument clock. The redraw computes the visible ring window once and reuses it for both passes over the 240 columns. Tests cover the previous 32-bit boundary, ring expiry, HOLD marks and changing span.
- **Generator timing.** The search now considers a prescaler whose ideal reload falls just beyond the 16-bit register. It stops after exchanging the two divisor factors can only repeat or worsen candidates. In a host benchmark of 300 fractional requests at a 200 MHz timer clock, the median of three runs fell from 3.00 s to 0.019 s with the same checksum of selected registers. The benchmark used GCC 13.3 with `-Os` and requests from 5.0113 to 8.39 Hz.
- **C runtime heap.** Both STM32 images now use linker-defined allocation bounds. Newlib reports `ENOMEM` when a request would pass the end of SRAM4 in the application or enter the reserved 96 KiB stack in recovery. Failed requests preserve the previous break. LVGL continues to use its separate 60 KiB arena.
- **Storage and updates.** A read entirely within a dirty erase block uses its newer RAM contents. Host writes replacing a full 4 KiB block skip the preliminary read used to preserve untouched bytes. NOR verification still runs. Legacy image validation skips the second streaming CRC used only by bundled images.
- **Companion file transfer.** The HTTP worker now waits for a UART reply, portal shutdown or the existing timeout on a static semaphore. This removes the 10 ms polling wakeup while a request is pending. The companion application spends 80 additional bytes of static RAM on the change.

The STM32 firmware and host targets select C++23 for C++ translation units with the existing Arm GCC 12.3 toolchain on device. C dependencies retain their own language mode. The companion's ESP-IDF build already selects GNU C++23. The STM32 builds keep size optimization, LTO, disabled exceptions and disabled RTTI.

The JSF AV C++ review used Rev C as advisory guidance. Rules 203 and 204 informed the arithmetic and volatile side-effect changes. Rules 206 and 208 informed the allocation and exception review. OpenOSC uses placement construction in fixed memory, a bounded LVGL heap, compiler-specific sections, MMIO and assembly. Formal compliance would require a rule-by-rule assessment, documented deviations and target verification.

## Linked footprint

PlatformIO reports the following byte counts. Its STM32 RAM figure covers ordinary data and BSS. Dedicated banks and reserved stack require inspection of the ELF and linker script.

| Image | Flash before | Flash after | RAM before | RAM after |
| --- | ---: | ---: | ---: | ---: |
| ZT706S application | 1,348,480 | 1,333,520 | 79,524 | 79,524 |
| ZT703S application | 1,360,704 | 1,345,816 | 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 |

On ZT706S the linker leaves 50,264 bytes between the end of BSS and the stack top. This is a reservation, and live stack depth still needs device measurement. AXI sections reach 1,048,480 bytes into the 1 MiB bank, leaving **96 bytes**. The AHB record bank uses its full 128 KiB. In SRAM4, 1,856 bytes remain between the application's C heap start and its enforced limit. The firmware passes the existing section and stack assertions. [Application linker script](../ld/application.ld)

## Verification and open findings

The four STM32 images and both public ESP32-C3 images built. All seven release assets passed SHA-256 verification. All 130 native test cases and 39 Python tests passed. The screen suite passed under AddressSanitizer, LeakSanitizer and UndefinedBehaviorSanitizer in English, Chinese, Russian and Spanish. Board configuration, translations and localized font coverage passed their consistency checks. Additional host harnesses exercised NOR cache ownership and failed flush retries, mailbox replies, stale responses, timeout and shutdown, and heap growth and shrinkage at both bounds and at the extremes of `ptrdiff_t`.

- **USB command loss remains open.** A CDC DTR transition can rearm a ready OUT buffer, and session synchronization resets the parser. That provides a code path consistent with the reported lost mode command. A transport fix needs to preserve completed commands and isolate partial commands and replies across sessions. The upstream reproduction used a ZT703S. [USB issue 177](https://github.com/bve/OpenOSC/issues/177)
- **Bench validation is outstanding.** No handheld was available during this review. ZT706S trigger stability, generator output and acknowledgments, USB close/reopen behavior, installed-image boot, NOR power-loss behavior and battery current remain unmeasured. Host timings establish an algorithmic improvement. A power comparison needs the same clock profile, brightness, acquisition settings and companion state on the device.
18 changes: 15 additions & 3 deletions include/openosc/measurement/dmm/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ class History {
uint64_t spanUs() const { return uint64_t(SpanSeconds[span_]) * 1000000; }
// Column `index` (0 oldest .. Columns-1 newest) of the window ending at endUs (or at the newest
// reading, when that is later); false without readings in it.
class Window {
public:
const Column *column(unsigned index) const;
private:
friend class History;
const Column *ring_ = nullptr;
unsigned first_ = 0, end_ = 0, start_ = 0;
};
Window window(uint64_t endUs) const;
bool column(unsigned index, uint64_t endUs, Column &output) const;
bool empty() const { return !any_; }
void reset() {
Expand All @@ -92,14 +101,17 @@ class History {
// Mark `index` (0..MaxMarks-1) as a column of the window ending at endUs (as column()); false: none there.
bool markColumn(unsigned index, uint64_t endUs, unsigned &column) const {
if (index >= MaxMarks || !marks_[index]) return false;
const uint32_t end = slotOf(endUs > latestUs_ ? endUs : latestUs_), slot = slotOf(marks_[index] - 1);
const uint64_t end = slotOf(endUs > latestUs_ ? endUs : latestUs_), slot = slotOf(marks_[index] - 1);
if (slot > end || end - slot >= Columns) return false;
column = Columns - 1 - (end - slot);
column = Columns - 1 - unsigned(end - slot);
return true;
}

private:
uint32_t slotOf(uint64_t us) const { return uint32_t(us * Columns / spanUs()); }
uint64_t slotOf(uint64_t us) const {
const uint64_t span = spanUs();
return (us / span) * Columns + (us % span) * Columns / span;
}
static void merge(Column &into, const Column &from);
Column columns_[Columns]; // By slot % Columns.
uint64_t marks_[MaxMarks]{}; // Trend times + 1 (0: none), a ring from nextMark_.
Expand Down
10 changes: 6 additions & 4 deletions include/openosc/ui/scope/column_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "openosc/acquisition/frame.hpp"
#include "openosc/ui/scope/options.hpp"
#include "openosc/ui/scope/viewport.hpp"
#include <optional>

namespace openosc::plot {
// The next frame's column reductions, done ahead while the display waits on DMA2D (RenderIdle,
Expand All @@ -21,18 +22,19 @@ class ColumnCache {
return same(frame, viewport) ? done_ : 0;
}
const scope::ColumnStats (&columns(unsigned x) const)[2] { return stats_[x]; }
void clear() { valid_ = false; done_ = 0; }
void clear() { viewport_.reset(); done_ = 0; }
static bool applies(const scope::FrameView &frame, const Options &options, const Viewport &viewport);
static bool reduce(const scope::FrameView &frame, uint32_t first, uint32_t last, scope::ColumnStats (&out)[2]);

private:
bool same(const scope::FrameMetadata &m, const Viewport &v) const {
return valid_ && m.sequence == sequence_ && m.timestampUs == timestamp_ && m.triggerIndex == trigger_ && v == viewport_;
return viewport_ && m.sequence == sequence_ && m.timestampUs == timestamp_ && m.triggerIndex == trigger_ && v == *viewport_;
}
uint32_t sequence_ = 0, trigger_ = 0, done_ = 0;
uint64_t timestamp_ = 0;
Viewport viewport_{};
bool valid_ = false;
// An empty cache has no viewport. This also keeps its zero-initialized
// column array in .bss instead of copying it from flash at startup.
std::optional<Viewport> viewport_;
scope::ColumnStats stats_[MaximumWidth][2];
};
} // namespace openosc::plot
2 changes: 2 additions & 0 deletions ld/application.ld
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ SECTIONS {
.generator (NOLOAD) : { . = ALIGN(32); KEEP(*(.generator)) } > SRAM4
.settings_workspace (NOLOAD) : { . = ALIGN(32); KEEP(*(.settings_workspace)) . = ALIGN(32); } > SRAM4
. = ALIGN(8); _end = .; PROVIDE(end = .);
_heap_limit = ORIGIN(SRAM4) + LENGTH(SRAM4);
/* ITCM (CPU and MDMA only, no DMA1/2 or DMA2D): the protocol decoder's workspace (its job, lease and
two result sets) and, in OPENOSC_USB_TRACE builds, the trace ring. Reset_Handler enables ITCM and
zeroes both in 64-bit ECC words before any constructor runs (the job is built in place later). */
Expand All @@ -68,6 +69,7 @@ SECTIONS {
.dmm_log (NOLOAD) : { . = ALIGN(8); _sdmm_log = .; KEEP(*(.dmm_log)) . = ALIGN(8); _edmm_log = .; } > ITCM
/DISCARD/ : { *(.comment) *(.note*) }
ASSERT(_ebss + 49152 < _estack, "Application leaves less than 48 KiB stack")
ASSERT(_end >= ORIGIN(SRAM4) && _end <= _heap_limit, "C heap must start in SRAM4")
ASSERT(ADDR(.runtime_vectors) == ORIGIN(RAM) && SIZEOF(.runtime_vectors) == 1024, "Runtime vectors must open DTCM")
ASSERT(ADDR(.framebuffer) == 0x24000000, "Panel framebuffer address changed")
ASSERT(SIZEOF(.dma_data) >= 1024, "Initialized USB DMA buffers were not linked")
Expand Down
3 changes: 2 additions & 1 deletion ld/recovery_common.ld
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ SECTIONS {
_sidata = LOADADDR(.data);
.bss (NOLOAD) : { . = ALIGN(1024); _sbss = .; *(.bss*) *(COMMON) . = ALIGN(8); _ebss = .; } > RAM
. = ALIGN(8); _end = .; PROVIDE(end = .);
_heap_limit = _estack - 96K;
/DISCARD/ : { *(.comment) *(.note*) }
ASSERT(_ebss + 98304 < _estack, "Recovery RAM leaves less than 96 KiB stack")
ASSERT(_end < _heap_limit, "Recovery RAM leaves less than 96 KiB stack")
ASSERT(LOADADDR(.data) + SIZEOF(.data) <= ORIGIN(BOOT) + LENGTH(BOOT), "Recovery exceeds fixed 128 KiB reservation")
/* The image's own vector table (vectors.S) is taken before the code is copied: its handler
must lie in the image, not in the relocated CODE. */
Expand Down
33 changes: 22 additions & 11 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ platform_packages = toolchain-gccarmnoneeabi@1.120301.0
board = zt703s
custom_openosc_image = recovery
extra_scripts =
pre:scripts/cxx_standard.py
pre:scripts/build.py
post:scripts/linker_dependencies.py
build_unflags = -O2 -Og
Expand Down Expand Up @@ -115,25 +116,26 @@ build_src_filter =
-<generator/output.cpp>
-<measurement/dmm/serial_output.cpp>

[host_tests]
build_flags =
-DUNITY_INCLUDE_DOUBLE
-Iinclude
-Wall
-Wextra
-Wno-unused-parameter

; Host unit tests: `pio test -e native` (not part of `pio run`). Only hardware-independent sources
; are compiled; the [env] settings for the device builds are overridden here.
[env:native]
platform = native
platform_packages =
extra_scripts =
extra_scripts = pre:scripts/cxx_standard.py
board_build.ldscript =
test_framework = unity
test_ignore = test_ui_*
test_build_src = yes
build_unflags =
build_flags =
-std=gnu++17
-DOPENOSC_BOARD=703
-DUNITY_INCLUDE_DOUBLE
-Iinclude
-Wall
-Wextra
-Wno-unused-parameter
build_flags = ${host_tests.build_flags} -DOPENOSC_BOARD=703
build_src_filter =
-<*>
+<decode/result.cpp>
Expand All @@ -142,6 +144,8 @@ build_src_filter =
+<decode/protocols/i2c.cpp>
+<decode/protocols/spi.cpp>
+<data/units.cpp>
+<measurement/dmm/history.cpp>
+<platform/timer_plan.cpp>
+<measurement/dmm/packet.cpp>
+<measurement/dmm/decoder.cpp>
+<measurement/dmm/function.cpp>
Expand All @@ -154,22 +158,29 @@ build_src_filter =
+<storage/font_pack_file.cpp>
+<i18n/>

[env:native_zt706s]
extends = env:native
build_flags = ${host_tests.build_flags} -DOPENOSC_BOARD=706
test_filter =
test_dmm_packet
test_dmm_ranges
test_update_package

; The localized text on LVGL's own layout (UTF-8 measurement, fallback fonts, the choice of versions and
; faces, every locale character drawable), every Settings page in every language through the real views,
; and the language setting in the preferences file: LVGL from vendor/, the firmware's fonts,
; test/support/lv_conf.h, the host text diagnostics.
[env:native_ui]
platform = native
platform_packages =
extra_scripts =
extra_scripts = pre:scripts/cxx_standard.py
board_build.ldscript =
test_framework = unity
test_filter = test_ui_*
test_build_src = yes
lib_deps = symlink://vendor/lvgl
build_unflags =
build_flags =
-std=gnu++17
-Itest/support
-DLV_CONF_INCLUDE_SIMPLE
-DOPENOSC_TEXT_DIAGNOSTICS
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
]
env.Append(CPPPATH=[str(root / path) for path in include_dirs])
env.Append(ASFLAGS=["-mfloat-abi=hard", "-mfpu=fpv5-d16"])
env.Append(CXXFLAGS=["-std=gnu++17", "-fno-exceptions", "-fno-rtti", "-fno-threadsafe-statics"])
env.Append(CXXFLAGS=["-fno-exceptions", "-fno-rtti", "-fno-threadsafe-statics"])
env.Append(LINKFLAGS=["-flto", "-nostartfiles", "-mfloat-abi=hard", "-mfpu=fpv5-d16",
"--specs=nano.specs", "--specs=nosys.specs",
"-Wl,-Map," + env.subst("$BUILD_DIR/firmware.map")])
Expand Down
5 changes: 5 additions & 0 deletions scripts/cxx_standard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Use the same C++ dialect for the STM32 images and their host tests."""

Import("env")

env.Append(CXXFLAGS=["-std=gnu++23"])
2 changes: 1 addition & 1 deletion scripts/test_ui_screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"-DLV_CONF_INCLUDE_SIMPLE=1", "-DOPENOSC_BOARD=703", "-DOPENOSC_TEXT_DIAGNOSTICS=1", "-Itest/support",
"-Ivendor/lvgl", "-Iinclude", f"-I{cmsis_dsp.INCLUDE}", "-Ivendor/cmsis", *[f"-D{d}" for d in cmsis_dsp.DEFINES]]
CC = ["gcc", "-std=c99", *FLAGS]
CXX = ["g++", "-std=c++17", "-Wall", "-Wextra", "-Werror", *FLAGS]
CXX = ["g++", "-std=c++23", "-Wall", "-Wextra", "-Werror", *FLAGS]


def compile_one(command, source):
Expand Down
2 changes: 1 addition & 1 deletion scripts/ui_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"src/acquisition/measurements.cpp", "src/acquisition/auto_setup.cpp", "src/acquisition/signal_band.cpp",
"src/acquisition/tone_estimate.cpp", "src/acquisition/spectrum.cpp", "src/acquisition/spectrum_peak.cpp",
"src/generator/waveform.cpp",
"src/platform/timer_plan.cpp", "src/measurement/dmm/session.cpp", "src/measurement/dmm/hold.cpp",
"src/platform/timer_plan.cpp", "src/measurement/dmm/session.cpp", "src/measurement/dmm/history.cpp", "src/measurement/dmm/hold.cpp",
"src/measurement/dmm/statistics.cpp", "src/measurement/dmm/function.cpp", "src/measurement/dmm/key_command.cpp",
"src/measurement/dmm/ranges.cpp", "src/measurement/dmm/decoder.cpp", "src/measurement/dmm/packet.cpp"]

Expand Down
Loading