OTP Programming Reference
OTP API Reference
API |
Description |
Operating Zone |
|---|---|---|
OTP_Read8 |
Read a single byte from the OTP physical zone. |
Physical Zone |
OTP_Read32 |
Read 4 bytes from the OTP physical zone. |
Physical Zone |
OTP_Write8 |
Write a single byte to the OTP physical zone. |
Physical Zone |
OTP_LogicalRead |
Read the OTP logical map zone by length. |
Logical Zone |
OTP_LogicalWrite |
Write to the OTP logical map zone address by length. |
Logical Zone |
OTP_LogicalGetRemain |
Get the remaining available length of OTP in the logical map zone. |
Logical Zone |
OTP_SetCRC |
Set the CRC check value for the secure zone. |
Physical Zone |
OTP_Read8
Item |
Description |
|---|---|
Function |
Read a single byte from the OTP physical zone. |
Parameters |
|
Return Value |
Read operation result
|
OTP_Read32
Item |
Description |
|---|---|
Function |
Read 4 bytes from the OTP physical zone. |
Parameters |
|
Return Value |
Read operation result
|
OTP_Write8
Item |
Description |
|---|---|
Function |
Write a single byte to the OTP physical zone. |
Parameters |
|
Return Value |
Write operation result
|
OTP_LogicalRead
Item |
Description |
|---|---|
Function |
Read the OTP logical map zone by length. |
Parameters |
|
Return Value |
Read operation result
|
OTP_LogicalWrite
Item |
Description |
|---|---|
Function |
Write to the OTP logical map zone address by length. |
Parameters |
|
Return Value |
Write operation result
|
OTP_LogicalGetRemain
Item |
Description |
|---|---|
Function |
Get the remaining available length of OTP in the logical map zone. |
Parameters |
None |
Return Value |
Remaining available length |
OTP_SetCRC
Item |
Description |
|---|---|
Function |
Set the CRC check value for the secure zone. |
Parameters |
None |
Return Value |
Operation result
|
OTP API Usage
Logical Zone
If the programming address is within the System Data Zone (0x000-0x01F) , refer to System Data Zone .
If the address is outside the System Data Zone, assuming the goal is to program the value of logical address 0x22[1] to 1, follow the steps below:
Read the original value of logical address 0x22 and check the function return value.
u8 data_read; int ret; ret = OTP_LogicalRead(&data_read, 0x22, 1);
Assume the data read from logical address 0x22 in step 1 is 0xA0. Perform an OR operation between 0xA0 and the target bit 0x22[1], keeping the rest of the data at default values. Therefore, the new value to be written is 0xA2.
Write the new value 0xA2 to logical address 0x22 and check the function return value.
u8 data_written = 0xA2; int ret; ret = OTP_LogicalWrite(0x22, 1, &data_written);
Read the value at logical address 0x22 again to check whether the write operation was successful.
Caution
When programming the system data zone (0x000-0x01F), refer to System Data Zone ; otherwise, incorrect programming may occur!
Physical Zone
Program the value of physical address 0x02[1] to 0 by following steps:
Read the original value of physical address 0x02 and check the return value.
u8 data_read; int ret; ret = OTP_Read8(0x2, &data_read);
Assume the data read from physical address 0x02 in step 1 is 0xAF. Perform an AND operation between 0xAF and the target bit 0x02[1], keeping the rest of the data at default values. Therefore, the new value to be written is 0xAD.
Write the new value 0xAD to physical address 0x02 and check the return value.
u8 data_written = 0xAD; int ret; ret = OTP_Write8(0x2, data_written);
4.Read the value at physical address 0x02 again to verify if the write was successful.
OTP Serial Port Programming
Program the physical and logical zones of the OTP via the serial port.
Logical Zone
Use the following commands to perform read and write operations on the logical zone.
Operation |
Command |
Description |
|---|---|---|
Read |
AT+OTP=RMAP |
Read the entire logical zone |
Write |
AT+OTP=WMAP,<address>,<length>,<data> |
Write to a specified address in the logical zone
Note The length of the data string must be even and should not include the 0x prefix. |
If the programming address is within the System Data Zone (0x000-0x01F) , refer to System Data Zone .
If the address is outside the System Data Zone, assuming the goal is to program the value of logical address 0x22[1] to 1, follow the steps below:
Read the logical map and check the original value at logical address 0x22.
AT+OTP=RMAP EFUSE[000]: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff EFUSE[010]: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff EFUSE[020]: ff ff a0 ff ff ff ff ff ff ff ff ff ff ff ff ff EFUSE[030]: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ...
Assume the data read from logical address 0x22 in step 1 is 0xA0. Perform an OR operation between 0xA0 and the target bit 0x22[1], keeping the rest of the data at default values. Therefore, the new value to be written is 0xA2.
Write the new value 0xA2 to logical address 0x22.
AT+OTP=WMAP,0x22,0x1,A2 [ATCMD_OTP-I] efuse wmap write len:1, string len:2
Read the data again to verify if the write operation was successful.
AT+OTP=RMAP EFUSE[000]: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff EFUSE[010]: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff EFUSE[020]: ff ff a2 ff ff ff ff ff ff ff ff ff ff ff ff ff EFUSE[030]: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ...
Caution
When programming the system data zone (0x000-0x01F), refer to :ref:` System Data Zone <otpc_logical_system_data_zone>` ; otherwise, incorrect programming may occur!
Physical Zone
Use the following commands to perform read and write operations on the physical zone.
Operation |
Command |
Description |
|---|---|---|
Read |
AT+OTP=RRAW |
Read the entire physical zone |
Write |
AT+OTP=WRAW,<address>,<length>,<data> |
Write to a specified address in the physical zone
Note The length of the data string must be even and should not include the 0x prefix. |
To program the value of physical address 0x02[1] to 0, follow these steps:
Read the physical map to check the original value at physical address 0x02.
AT+OTP=RRAW RawMap[000]: ff ff af ff ff ff ff ff ff ff ff ff ff ff ff ff RawMap[010]: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff RawMap[020]: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff RawMap[030]: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ...
Assume the data read from physical address 0x02 in step 1 is 0xAF. Perform an AND operation between 0xAF and the target bit 0x02[1], keeping the rest of the data at default values. The new value to be written is 0xAD.
Write the new value 0xAD to physical address 0xAD.
AT+OTP=WRAW,0x2,0x1,AD [ATCMD_OTP-I] efuse wraw write len:1, string len:2 wraw: 2 ad
Read the data again to verify if the write operation was successful.
Note
The RF calibration tool uses the command iwpriv to program the OTP, but it is not recommended for other tools to use this command for OTP programming.