OTP Module API Manual#
Overview#
CanMV K230 provides the OTP (One-Time Programmable) class for reading chip OTP data and querying the read/write lock status of a specified address.
The OTP object is a singleton object, and repeated calls to OTP() return the same instance.
API Introduction#
The OTP class is located under the machine module.
Example#
from machine import OTP
import binascii
otp = OTP()
data = otp.read(0x000, 32)
print(binascii.hexlify(data))
lock = otp.get_lock(0x000)
if lock == OTP.NA:
print("No Access")
elif lock == OTP.RO:
print("Read Only")
elif lock == OTP.RW:
print("Read Write")
Constructor#
otp = OTP()
Parameters
None
Return Value
Returns the OTP singleton object.
read Method#
data = otp.read(addr, length)
Function#
Reads byte data from the specified address in OTP.
Parameters
addr: The starting address to read from, ranging from0x000to0xFFF, must be 4-byte aligned.length: The read length, ranging from 1 to 1024 bytes.
Return Value
Returns the read OTP data, of type bytes.
Restrictions
addr + lengthcannot exceed the total OTP range.A single read cannot cross the
0x400boundary.
get_lock Method#
lock = otp.get_lock(addr)
Function#
Query the read/write lock status of the specified OTP address.
Parameters
addr: The OTP address to query, ranging from0x000to0xFFF, must be 4-byte aligned.
Return Value
Returns a lock status integer, which can be compared with the following constants:
Constant |
Value |
Description |
|---|---|---|
|
0 |
No Access |
|
1 |
Read Only |
|
2 |
Read Write |
Constants#
Constant |
Description |
|---|---|
|
OTP address is not accessible |
|
OTP address is read-only |
|
OTP address is readable and writable |
Notes#
OTP may store device security configuration or identity-related information. Please confirm the usage scenario before printing or saving.
Currently,
machine.OTPonly provides read and lock status query interfaces, and does not provide write or lock interfaces.
