Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c8c74e1
Add the STANDALONE external frame sync role
sb-lxn Nov 12, 2026
0ece0e2
Pipeline: start STANDALONE devices with the frame sync masters
sb-lxn Nov 12, 2026
aa2182c
Test on-board frame sync in the STANDALONE role
sb-lxn Nov 12, 2026
24563ef
Merge remote-tracking branch 'origin/develop' into feat/aux-controlle…
sb-lxn Nov 16, 2026
3457839
Bump rvc4 device
sb-lxn Nov 16, 2026
f440886
DeviceBase: document the frame sync role results
sb-lxn Nov 16, 2026
86b5a5a
bump rvc4 device
sb-lxn Nov 16, 2026
f844a30
Merge remote-tracking branch 'origin/develop' into feat/aux-controlle…
sb-lxn Nov 26, 2026
2eb8e79
FsyncController: keep the frame sync role in one RoleState
sb-lxn Nov 12, 2026
1d30b0f
FsyncController: write CONFIG 0 at start, apply the role when the pip…
sb-lxn Nov 12, 2026
712cd57
FsyncController: add the STANDALONE frame sync role
sb-lxn Nov 12, 2026
18dd10e
FsyncController: keep on-board sync when the FSYNC pin is unavailable
sb-lxn Nov 12, 2026
ed6a118
FsyncController: name the holder of a busy FSYNC pin
sb-lxn Nov 12, 2026
912f2f0
PipelineBuilder: check a forced frame sync role before building the n…
sb-lxn Nov 12, 2026
68b0f5c
FsyncController: read CONFIG back before keeping on-board sync
sb-lxn Nov 13, 2026
106fffa
FsyncController: fail an explicit role when fsync-stm cannot be opened
sb-lxn Nov 26, 2026
f3efcac
FsyncController: fail an explicit role after an earlier controller fa…
sb-lxn Nov 26, 2026
ab52822
Merge remote-tracking branch 'origin/develop' into feat/aux-controlle…
sb-lxn Nov 30, 2026
7533ac3
chore(rvc4): pass the comment lint in the FSYNC and aux connector code
sb-lxn Nov 30, 2026
1d96d47
Build the RVC4 firmware on Luxonis OS 1.50.0
sb-lxn Nov 30, 2026
153e296
Rename the STANDALONE external frame sync role to ISOLATED
sb-lxn Dec 1, 2026
c464274
Refuse a frame sync role change while a pipeline runs
sb-lxn Dec 1, 2026
ef91a29
FsyncController: fail a forced role on a device without external fram…
sb-lxn Dec 1, 2026
314dfa3
FsyncController: tie EAGAIN and EBUSY to the connector state
sb-lxn Dec 1, 2026
f9339a2
Tests: check the RVC4 frame sync role rules on the host
sb-lxn Dec 1, 2026
cae43e3
Tests: require the isolated camera log in the ISOLATED frame sync case
sb-lxn Dec 1, 2026
227ab8a
FsyncController: apply AUTO_DETECT again at a later pipeline start
sb-lxn Dec 1, 2026
04fc419
DeviceBase: say when the frame sync role is final and what a SLAVE needs
sb-lxn Dec 1, 2026
9f729a7
Examples: apply the frame sync role before reading it
sb-lxn Dec 1, 2026
30db263
FsyncController: share the device tree string reader
sb-lxn Dec 1, 2026
a1c785e
FsyncController: keep linux/aux-connector.h out of AuxConnector.hpp
sb-lxn Dec 1, 2026
6b32d7f
DeviceBase: say that a controller failure lasts for the session
sb-lxn Dec 1, 2026
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
3 changes: 2 additions & 1 deletion bindings/python/src/pipeline/CommonBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@ void CommonBindings::bind(pybind11::module& m, void* pCallstack) {

externalFrameSyncRole.value("AUTO_DETECT", ExternalFrameSyncRole::AUTO_DETECT)
.value("MASTER", ExternalFrameSyncRole::MASTER)
.value("SLAVE", ExternalFrameSyncRole::SLAVE);
.value("SLAVE", ExternalFrameSyncRole::SLAVE)
.value("ISOLATED", ExternalFrameSyncRole::ISOLATED);

cameraSensorType.value("AUTO", dai::CameraSensorType::AUTO)
.value("COLOR", CameraSensorType::COLOR)
Expand Down
5 changes: 5 additions & 0 deletions bindings/python/tests/api_binding_coverage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,8 @@ def test_camera_control_parameters():
control.setAutoExposureRegion(dai.Rect(0.5, 0.5, 0.25, 0.25), binned)
assert (control.aeRegion.x, control.aeRegion.y, control.aeRegion.width, control.aeRegion.height) == (4000, 3000, 2000, 1500)
control.setStrobeExternal(3, 1)


def test_external_frame_sync_role_isolated():
assert dai.ExternalFrameSyncRole.ISOLATED.value == 2
assert dai.ExternalFrameSyncRole(2).name == "ISOLATED"
4 changes: 2 additions & 2 deletions cmake/Depthai/DepthaiDeviceRVC4Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ set(DEPTHAI_DEVICE_RVC4_VERSION "" CACHE STRING "RVC4 firmware package to downlo

# Prebuilt vendor module (licensee-only code of the RVC4 firmware) that a firmware build of device/rvc4 links:
# depthai-device-rvc4-vendor-<version>[-asan-ubsan|-tsan].tar.xz (cmake/DepthaiDeviceRvc4VendorDownloader.cmake)
set(DEPTHAI_DEVICE_RVC4_VENDOR_VERSION "0.0.1+a02c081ba91aee62cf1d449a088afe68be2f1998")
set(DEPTHAI_DEVICE_RVC4_VENDOR_VERSION "0.0.1+d5fce2f37c37c24e77abe5945e0a20fba9747c5f")

# Public build image of the RVC4 firmware (device/rvc4/docker/Dockerfile.sdk) that the build scripts of device/rvc4 use
# when DEPTHAI_DEVICE_SDK_IMAGE is not set: ghcr.io/luxonis/depthai-device-sdk:os-<Luxonis OS version>-<first 12
# characters of the commit of the vendor repository that made the public sysroot>. The sanitizer targets use the same
# tag with -dev.
# device/rvc4/docker/sdk-images.sh builds and pushes it; a fixed tag is never moved. The OS release of its sysroot must
# be the one of the vendor module above: the firmware build compares them.
set(DEPTHAI_DEVICE_RVC4_SDK_IMAGE "ghcr.io/luxonis/depthai-device-sdk:os-1.37.0-5aeb67fb4fc6")
set(DEPTHAI_DEVICE_RVC4_SDK_IMAGE "ghcr.io/luxonis/depthai-device-sdk:os-1.50.0-d5fce2f37c37")
2 changes: 2 additions & 0 deletions device/rvc4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ set(DEPTHAI_COMMON_SOURCES
src/utilities/GpuAvailability.cpp
src/utilities/RectangleRemapUtils.cpp
src/utilities/FsyncController.cpp
src/utilities/FsyncRole.cpp
src/utilities/AuxConnector.cpp
src/pipeline/PipelineBuilder.cpp
src/pipeline/node/XLinkOut.cpp
src/pipeline/node/XLinkIn.cpp
Expand Down
11 changes: 9 additions & 2 deletions device/rvc4/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ void parseAssetsToAssetManager(dai::Pipeline& pipeline, dai::Assets& assets) {

std::function<std::tuple<bool, std::string>()> waitForDeviceReady = []() -> std::tuple<bool, std::string> {
try {
dai::gate::FsyncController::getInstance().applyPendingRole();
if (dai::gate::FsyncController::getInstance().supportsExternalFrameSyncMode() &&
dai::gate::FsyncController::getInstance().isOk())
{
Expand All @@ -536,7 +537,9 @@ std::function<std::tuple<bool, std::string>()> waitForDeviceReady = []() -> std:
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
if(!dai::gate::FsyncController::getInstance().isExternalFrameSyncSignalPresent()) {
return {false, "Slave was unable to detect or lock onto external frame sync signal."};
return {false,
"Slave was unable to detect or lock onto external frame sync signal. Check that the device on the other end of the cable runs as "
"MASTER."};
}
}
}
Expand All @@ -548,8 +551,12 @@ std::function<std::tuple<bool, std::string>()> waitForDeviceReady = []() -> std:

std::function<std::tuple<bool, std::string>(dai::ExternalFrameSyncRole)> setExternalFrameSyncRole =
[](dai::ExternalFrameSyncRole role) -> std::tuple<bool, std::string> {
if(pipeline.isRunning()) { // A CONFIG change while the cameras stream can stop the frames and abort CamX
return {false,
fmt::format("Cannot set external frame sync role {} while a pipeline runs. Set the role before the pipeline starts.", dai::toString(role))};
}
try {
dai::gate::FsyncController::getInstance().setExternalFrameSyncRole(role, true);
dai::gate::FsyncController::getInstance().setExternalFrameSyncRole(role);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M1. A role change from STANDALONE to MASTER while the cameras stream crashes the firmware.

The RPC applies the role at once and has no check for a running pipeline. STANDALONE is the first role in which a pipeline streams with CONFIG 0, so develop cannot reach this state. The RPC returns (True, ''). Then no frames come for 10 s, CamX aborts in ExtensionModule::RecoveryThread (SIGABRT), and the host reports Device ... has crashed. Seen in 2 of 4 sessions on an OAK4-LITE with OS 1.49.1 (0 of 5 changes on an OAK4-D with OS 1.44.0). MASTER to STANDALONE, MASTER to SLAVE and MASTER to MASTER while running never crashed.

Smallest fix: In setExternalFrameSyncRole, refuse a change while a pipeline runs. Or keep the role and apply it at the next start (waitForDeviceReady already calls applyPendingRole). If live changes must stay, ask the STM and OS owners if a CONFIG change while streaming is supported.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refusing to change role while running is the best fix here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c464274. The setExternalFrameSyncRole RPC returns false while a pipeline runs and writes nothing: Cannot set external frame sync role {ROLE} while a pipeline runs. Set the role before the pipeline starts. On an OAK4-LITE R1 PoE, ISOLATED to MASTER, MASTER to MASTER and MASTER to ISOLATED while streaming each returned that text. The role read stayed, 510 Sync groups came in the 17 s after the call, and nothing crashed.

} catch (const std::exception& ex) {
return {false, ex.what()};
}
Expand Down
11 changes: 10 additions & 1 deletion device/rvc4/src/pipeline/PipelineBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,29 @@ void installMultiDeviceCalibration(const Pipeline& pipeline) {
}

void validateFsync1() {
auto roleState = FsyncController::getInstance().getRoleState();
if(auto error = roleState && externalRoleForced(*roleState) ? setRoleError(*roleState) : std::nullopt) {
throw std::runtime_error(*error);
}

auto isExternalStrobeEnabled = FsyncController::getInstance().getExternalStrobeEnable();
auto fsyncRole = FsyncController::getInstance().getExternalFrameSyncRole();
auto fsyncOk = FsyncController::getInstance().isOk();

if ((fsyncRole != ExternalFrameSyncRole::MASTER || !fsyncOk) &&
isExternalStrobeEnabled)
{
if(auto error = roleState ? strobeNeedsPinError(*roleState) : std::nullopt) {
throw std::runtime_error(*error);
}
throw std::runtime_error("External strobe requires the device to be set in MASTER mode.");
}
}

void validateFsync2() {
auto numFsyncConsumers = FsyncController::getInstance().getNumFsyncConsumers();
auto isExternalFsyncExplicit = FsyncController::getInstance().isExternalFrameSyncRoleSetExplicitly();
auto roleState = FsyncController::getInstance().getRoleState();
bool isExternalFsyncExplicit = roleState && externalRoleForced(*roleState);
auto isExternalStrobeEnabled = FsyncController::getInstance().getExternalStrobeEnable();
auto fsyncOk = FsyncController::getInstance().isOk();

Expand Down
2 changes: 2 additions & 0 deletions device/rvc4/src/pipeline/node/Camera/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,8 @@ void Camera::buildStage2() {
logger->info("This device is a FSync master!");
} else if(fsyncRole == dai::ExternalFrameSyncRole::SLAVE) {
logger->info("This device is a FSync slave!");
} else if(fsyncRole == dai::ExternalFrameSyncRole::ISOLATED) {
logger->info("This device runs FSync isolated, the FSYNC pin is not used.");
} else {
throw std::runtime_error("Illegal fsync role detected!");
}
Expand Down
170 changes: 170 additions & 0 deletions device/rvc4/src/utilities/AuxConnector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#include "utilities/AuxConnector.hpp"

#include <fcntl.h>
#include <linux/aux-connector.h>
#include <linux/gpio.h>
#include <sys/ioctl.h>
#include <unistd.h>

#include <algorithm>
#include <cerrno>
#include <cstring>
#include <fstream>
#include <system_error>

#include "utilities/OSUtils.hpp"

namespace dai {
namespace aux {

namespace {

template <std::size_t N>
std::string fixedString(const char (&chars)[N]) {
return std::string(chars, strnlen(chars, N)); // A kernel string that fills its whole array has no NUL
}

struct FileDescriptor {
int fd;
explicit FileDescriptor(int fd) : fd(fd) {}
FileDescriptor(const FileDescriptor&) = delete;
FileDescriptor& operator=(const FileDescriptor&) = delete;
~FileDescriptor() {
if(fd >= 0) {
close(fd);
}
}
};

} // namespace

bool fsyncLinkedToConnector(const std::filesystem::path& deviceTree) {
auto node = gate::readDeviceTreeString(deviceTree / "aliases/stm_fsync");
if(!node || node->empty()) {
return false;
}
std::error_code ec;
if(!std::filesystem::exists(deviceTree / std::filesystem::path(*node).relative_path() / "luxonis,aux-connector", ec)) {
return false;
}
auto status = gate::readDeviceTreeString(deviceTree / "aux-connector/status");
return !status || *status == "okay" || *status == "ok";
}

bool connectorBound(const std::filesystem::path& device) {
int fd = open(device.c_str(), O_RDONLY | O_CLOEXEC);
if(fd < 0) {
return false;
}
close(fd);
return true;
}

Pin parsePin(const aux_pin_info& info, const aux_pin_state& state) {
Pin pin{info.pin, fixedString(info.label), {}, std::nullopt, {NoOwner{}, (state.flags & AUX_PIN_FLAG_LINE) != 0}};
for(uint32_t i = 0; i < std::min<uint32_t>(info.nfuncs, AUX_MAX_PIN_FUNCS); i++) {
pin.functions.push_back(info.funcs[i].function);
}
if(info.gpio.chip[0] != '\0') {
pin.gpio = GpioLineRef{fixedString(info.gpio.chip), info.gpio.offset};
}
switch(state.owner.type) {
case AUX_OWNER_ME:
case AUX_OWNER_OTHER:
pin.state.owner = ProcessOwner{static_cast<pid_t>(state.owner.pid)};
break;
case AUX_OWNER_KERNEL:
pin.state.owner = KernelOwner{fixedString(state.owner.name)};
break;
default:
break;
}
return pin;
}

std::optional<Pin> findPinWithFunction(const std::vector<Pin>& pins, uint32_t function) {
auto pin = std::find_if(pins.begin(), pins.end(), [function](const Pin& candidate) {
return std::find(candidate.functions.begin(), candidate.functions.end(), function) != candidate.functions.end();
});
if(pin == pins.end()) {
return std::nullopt;
}
return *pin;
}

std::variant<std::vector<Pin>, int> readConnector(const std::filesystem::path& device) {
FileDescriptor connector(open(device.c_str(), O_RDONLY | O_CLOEXEC));
if(connector.fd < 0) {
return errno;
}
aux_info info{};
info.size = sizeof(info);
if(ioctl(connector.fd, AUX_IOC_INFO, &info) != 0) {
return errno;
}
aux_state state{};
state.size = sizeof(state);
if(ioctl(connector.fd, AUX_IOC_STATE, &state) != 0) {
return errno;
}
std::vector<Pin> pins;
for(uint32_t index = 0; index < std::min<uint32_t>(info.npins, AUX_MAX_PINS); index++) {
aux_pin_info pinInfo{};
pinInfo.size = sizeof(pinInfo);
pinInfo.pin = index;
if(ioctl(connector.fd, AUX_IOC_PIN_INFO, &pinInfo) != 0) {
return errno;
}
pins.push_back(parsePin(pinInfo, state.pins[index]));
}
return pins;
}

std::string readComm(pid_t pid) {
std::ifstream file("/proc/" + std::to_string(pid) + "/comm");
std::string comm;
std::getline(file, comm);
return comm;
}

std::string lineConsumer(const GpioLineRef& line) {
std::error_code ec;
for(std::filesystem::directory_iterator entry("/dev", ec), end; !ec && entry != end; entry.increment(ec)) {
if(entry->path().filename().string().rfind("gpiochip", 0) != 0) {
continue;
}
FileDescriptor chipFd(open(entry->path().c_str(), O_RDONLY | O_CLOEXEC));
gpiochip_info chip{};
if(chipFd.fd < 0 || ioctl(chipFd.fd, GPIO_GET_CHIPINFO_IOCTL, &chip) != 0 || fixedString(chip.label) != line.chip) {
continue;
}
gpio_v2_line_info lineInfo{};
lineInfo.offset = line.offset;
if(ioctl(chipFd.fd, GPIO_V2_GET_LINEINFO_IOCTL, &lineInfo) != 0) {
return "";
}
std::string consumer = fixedString(lineInfo.consumer);
return consumer == "?" ? "" : consumer; // gpiolib names the consumer of a request that gave none "?"
}
return "";
}

gate::PinUnavailable busyFsyncPin(const std::vector<Pin>& pins) {
gate::PinUnavailable busy{gate::PinProblem::Busy, "", std::nullopt};
auto pin = findPinWithFunction(pins, AUX_FUNC_FSYNC);
if(!pin) {
return busy;
}
busy.pinLabel = pin->label;
if(const auto* process = std::get_if<ProcessOwner>(&pin->state.owner)) {
busy.holder = gate::ProcessHolder{process->pid, readComm(process->pid)};
} else if(const auto* kernel = std::get_if<KernelOwner>(&pin->state.owner)) {
busy.holder = gate::KernelHolder{kernel->name};
} else if(pin->state.lineRequested) {
busy.holder = gate::LineHolder{"aux-" + pin->label, pin->gpio ? lineConsumer(*pin->gpio) : ""}; // The connector names its lines aux-<label>
}
return busy;
}

} // namespace aux
} // namespace dai
63 changes: 63 additions & 0 deletions device/rvc4/src/utilities/AuxConnector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#pragma once

#include <sys/types.h>

#include <cstdint>
#include <filesystem>
#include <optional>
#include <string>
#include <variant>
#include <vector>

#include "utilities/FsyncRole.hpp"

struct aux_pin_info;
struct aux_pin_state;

namespace dai {
namespace aux {

bool fsyncLinkedToConnector(const std::filesystem::path& deviceTree = "/proc/device-tree"); // fsync-stm looks the connector up only with this link

bool connectorBound(const std::filesystem::path& device = "/dev/aux-connector");

struct GpioLineRef {
std::string chip;
uint32_t offset;
};

struct NoOwner {};
struct ProcessOwner {
pid_t pid;
};
struct KernelOwner {
std::string name;
};
using Owner = std::variant<NoOwner, ProcessOwner, KernelOwner>;

struct PinState {
Owner owner;
bool lineRequested;
};

struct Pin {
uint32_t index;
std::string label;
std::vector<uint32_t> functions; // AUX_FUNC_*, empty on a fixed pin
std::optional<GpioLineRef> gpio;
PinState state;
};

Pin parsePin(const aux_pin_info& info, const aux_pin_state& state);
std::optional<Pin> findPinWithFunction(const std::vector<Pin>& pins, uint32_t function);

std::variant<std::vector<Pin>, int> readConnector(const std::filesystem::path& device = "/dev/aux-connector");

std::string readComm(pid_t pid);

std::string lineConsumer(const GpioLineRef& line);

gate::PinUnavailable busyFsyncPin(const std::vector<Pin>& pins);

} // namespace aux
} // namespace dai
13 changes: 4 additions & 9 deletions device/rvc4/src/utilities/DeviceTreeDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "FsyncController.hpp"
#include "utilities/ErrorMacros.hpp"
#include "utilities/OSUtils.hpp"
#include "camera/LuxonisSidechannel.hpp"
#include <luxonis_sidechannel_data.h>

Expand Down Expand Up @@ -129,19 +130,13 @@ void DeviceTreeDiscovery::EnumerateSTMFSync()
return;
}

std::string absPath;
try {
std::ifstream alias(fsyncAlias.c_str(), std::ios::binary);
std::stringstream aliasPath;
aliasPath << alias.rdbuf();
alias.close();
absPath = std::string(aliasPath.str().c_str()); // DTS names end with \0; going through c_str() drops it
} catch(...) {
auto absPath = gate::readDeviceTreeString(fsyncAlias);
if(!absPath) {
DAI_ERROR("Error reading stm fsync alias file!")
return;
}

std::string extFsyncOutProperty = deviceTreePath + absPath + "/external-output-pin";
std::string extFsyncOutProperty = deviceTreePath + *absPath + "/external-output-pin";

if (!fs::exists(extFsyncOutProperty)) {
DAI_ERROR("external-output-pin property not found for stm_fsync!");
Expand Down
Loading
Loading