Note

This is the documentation for the latest development branch and may refer to features that are not available in released versions. If you are looking for a specific release, use the drop-down menu on the left.

One-Time Programmable Storage (machine.OTP) API Reference

One-Time Programmable Storage (machine.OTP) API Reference#

Overview#

CanMV K230 provides the OTP (One-Time Programmable, one-time programmable memory) class for reading chip OTP data and querying the read/write lock status of a specified address.

The OTP object is a singleton. Repeated calls to OTP() return the same instance.

API Reference#

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#

Syntax

otp = OTP()

Parameters

None.

Return Value

Returns the OTP singleton object.

read#

Description

Reads byte data from the specified OTP address.

Syntax

data = otp.read(addr, length)

Parameters

Parameter Name

Description

addr

Starting address for reading, ranging from 0x000 to 0xFFF; must be 4-byte aligned

length

Read length, ranging from 1 to 1024 bytes

Return Value

Returns the read OTP data as bytes.

Notes

  • addr + length must not exceed the total OTP range.

  • A single read cannot cross the 0x400 boundary.

get_lock#

Description

Queries the read/write lock status of the specified OTP address.

Syntax

lock = otp.get_lock(addr)

Parameters

Parameter Name

Description

addr

OTP address to query, ranging from 0x000 to 0xFFF; must be 4-byte aligned

Return Value

Returns the lock status as an integer, which can be compared with the following constants:

Constant

Value

Description

OTP.NA

0

No Access, inaccessible

OTP.RO

1

Read Only, read-only

OTP.RW

2

Read Write, readable and writable

Constants#

Constant

Description

OTP.NA

OTP address is inaccessible

OTP.RO

OTP address is read-only

OTP.RW

OTP address is readable and writable

Notes#

  • The OTP may store device security configuration or identity-related information. Before printing or saving it, please confirm the use case.

  • The current machine.OTP only provides interfaces for reading and querying the lock status; it does not provide interfaces for writing or locking.

Comments list
Comments
Log in