Skip to content

Fixed writing to OTP registers smaller than 32 bits#26

Merged
JamesHuard merged 1 commit intoOpenDevicePartnership:mainfrom
Wassasin:fix/otp-small-registers
Oct 7, 2025
Merged

Fixed writing to OTP registers smaller than 32 bits#26
JamesHuard merged 1 commit intoOpenDevicePartnership:mainfrom
Wassasin:fix/otp-small-registers

Conversation

@Wassasin
Copy link
Copy Markdown
Contributor

@Wassasin Wassasin commented Oct 7, 2025

We have a single device-driver definition of the OTP fuse registers, but can access them both from shadow registers, as well as from the OTP ROM API. In the OTP ROM API implementation writing to registers smaller than 32 bits did not do anything. See #25.

This is due to calling chunks_exact with a size of 4, which does not yield any chunk if the remaining buffer cannot fit exactly that chunk:

for (i, chunk) in data.chunks_exact(4).enumerate() {
// Safety: we have chunks of exactly 4 bytes, hence the conversion to [u8; 4] is safe.
let word = u32::from_le_bytes(unsafe { chunk.try_into().unwrap_unchecked() });
self.otp.write_fuse(address + i as u32, word, self.mode_locked)?;
}

This PR streamlines how the OTP words are accessed between OTP ROM API and shadow registers, and adds a few tests to validate that it does so correctly.

@JamesHuard JamesHuard enabled auto-merge (squash) October 7, 2025 15:50
@JamesHuard JamesHuard merged commit 3116446 into OpenDevicePartnership:main Oct 7, 2025
7 checks passed
Comment thread libs/imxrt-rom/src/registers.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants