Skip to content
Merged
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
96 changes: 94 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ members = [
"kubos/services/isis-ants-service",
"kubos/test/integration/linux/isis-ants",
"services/payload-services/star-risc",
"services/payload-services/dosimeter",
"services/payload-services/snn-service",
"services/hardware-services/mram-service",
"services/hardware-services/fram-service",
"services/payload-services/dosimeter",
]

exclude = ["kubos/apis/nosengine-rust", "kubos/test/integration/nosengine-rust"]
Expand Down Expand Up @@ -116,6 +120,7 @@ default-members = [
"kubos/utils",
"services/simulator-services/clyde-3g-eps-simulator",
"services/hardware-services/mram-service",
"services/hardware-services/fram-service",
]

[workspace.package]
Expand Down
35 changes: 35 additions & 0 deletions services/hardware-services/fram-service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "fram-service"
edition = "2024"
version.workspace = true
description.workspace = true
documentation.workspace = true
repository.workspace = true
license.workspace = true

[features]
default = []
i2c = ["dep:embedded-hal", "dep:linux-embedded-hal"]
obc-tests = []

[[bin]]
name = "fram-obc-tests"
path = "obc-tests/src/main.rs"
required-features = ["i2c", "obc-tests"]

[dependencies]
async-graphql = "7.0.17"
async-graphql-axum = "7.0.17"
crc32fast = "1.5"
log = "^0.4.0"
thiserror = "2.0"

kubos-service = { path = "../../../kubos/services/kubos-service" }

embedded-hal = { version = "1.0", optional = true }
linux-embedded-hal = { version = "0.4", optional = true }

[dev-dependencies]
futures = "0.3"
serde_json = "1.0"
tempfile = "3"
70 changes: 70 additions & 0 deletions services/hardware-services/fram-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# FRAM Service

`fram-service` owns access to the 64-Kbit I2C F-RAM used for mission-critical
persistent state. It stores typed flags in a fixed-slot redundant layout and
mirrors selected values to U-Boot environment variables through `fw_printenv`
and `fw_setenv`.

The service uses a file backend by default so the GraphQL API, record CRCs, and
reconciliation behavior can be tested without hardware:

```toml
[fram-service]
backend = "file"
image_path = "/tmp/fram-service.img"
image_capacity_bytes = 8192
```

Flight hardware should use the I2C FRAM backend:

```toml
[fram-service]
backend = "i2c"
i2c_bus = "/dev/i2c-2"
i2c_addr = "0x50"
capacity_bytes = 8192
address_width_bytes = 2
max_transfer_bytes = 32
```

`i2c_addr` is the Linux 7-bit device address, not the 8-bit address byte shown
in the datasheet bus diagrams. For FM24CL64B, use `0x50` when A2/A1/A0 are all
low. Valid values are `0x50..0x57`; do not configure `0xA0` or `0xA1`.
If `i2cdetect` shows more than one responder in that range, confirm which one is
the FRAM before enabling writes.

On the current board schematic, the FRAM address pins are tied low, so the FRAM
is `0x50`. The RV-3028 RTC responds at `0x52`.

The FRAM is byte-addressable and has NoDelay writes. The backend does not add
EEPROM write-cycle polling or delays, but it still reports I2C errors so callers
can handle an OPD-off power domain. I2C bus speed is configured by the Linux
I2C controller/device tree; the FRAM part supports up to 1 MHz.

Mission applications should query this service rather than opening the I2C
device directly. The intended boot flow is:

1. Set system time from the RTC.
2. Call `reconcileMissionState(dryRun: false)`.
3. Read `missionState`.
4. Run deployment logic from the reconciled state.
5. Set completion flags through `setMissionFlag`.

## OBC hardware tests

Hardware-only tests live under `obc-tests/` so normal host tests never require a
real FRAM chip. To build, package, transfer, and run them:

```sh
services/hardware-services/fram-service/obc-tests/package.sh
transfer -d /home/kubos/fram-tests target/obc-tests/fram-service
```

Then on the OBC:

```sh
./run.sh
```

See `obc-tests/README.md` for the full cross-build commands, transfer flow, and
hardware test options.
20 changes: 20 additions & 0 deletions services/hardware-services/fram-service/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[fram-service]
backend = "file"
image_path = "/tmp/fram-service.img"
image_capacity_bytes = 8192

fw_printenv = "/usr/sbin/fw_printenv"
fw_setenv = "/usr/sbin/fw_setenv"

# Enable hardware mode by building with: cargo build -p fram-service --features i2c
# backend = "i2c"
# i2c_bus = "/dev/i2c-2"
# i2c_addr = "0x50"
# capacity_bytes = 8192
# address_width_bytes = 2
# max_transfer_bytes = 32
# I2C bus speed is configured by Linux/device-tree. The FRAM supports up to 1 MHz.

[fram-service.addr]
ip = "127.0.0.1"
port = 8091
Loading
Loading