How to use lib_otp3 on XS3 with RTOS? Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
littlefool
Junior Member
Posts: 5
Joined: Thu Mar 27, 2025 8:54 am

How to use lib_otp3 on XS3 with RTOS?

Post by littlefool »

I tried to use lib_otp3 on XS3 device with RTOS, but I failed. The program got stuck at otp_read(). How can I use lib_otp3 correctly? My XTC tool version is v15.3.1, and here is my test code:

Code: Select all

// main_tile1.c
OTPPorts otp_ports = OTP_PORTS_INITIALIZER;
unsigned otp_data = 0;
otp_read(&otp_ports, 0x3fd, &otp_data, 1);
rtos_printf("Read OTP data: %X\n", otp_data);
Any assistance will be appreciated!
View Solution
markp
Verified
Member++
Posts: 27
Joined: Thu Jan 10, 2019 6:07 pm

Post by markp »

Not sure hiow it might get stuck - you could get an exception thrown.
The port_enable() example below should fix that.
And you should use otp_read_differential() with a logical address on xcore.ai:

The following maps a physical to logical address:

logical = (physical & 0x1f) + ((physical & 0x3c0) >> 1)

and logical to physical:

physical = (logical & 0x1f) + ((logical & 0x1e0) << 1)



// This header is required for port_enable() below
#include <xcore/port.h>

const unsigned int otp_logical_addr = 0x1E0;
const unsigned int otp_value = 0x12345678;

OTPPorts otp = OTP_PORTS_INITIALIZER;

// This call to port_enable() must be made if the application is booted with the XMOS secure boot loader
port_enable(otp.otp_data_g);

if (otp_program_differential(&otp, otp_logical_addr, &otp_value, 1)) {
// Read back after successful write to confirm value is correct
unsigned data;

otp_read_differential(&otp, otp_logical_addr, &data, 1);
littlefool
Junior Member
Posts: 5
Joined: Thu Mar 27, 2025 8:54 am

Post by littlefool »

Many thanks to @markp, I can now read what I xburn to the OTP. Here is my simple test code `read_otp_test.c`:

Code: Select all

#include <stdio.h>
#include <xcore/parallel.h>
// This header is required for port_enable() below
#include <xcore/port.h>
#include "otp3.h"

OTPPorts otp_ports = OTP_PORTS_INITIALIZER;

// And you should use otp_read_differential() with a logical address on xcore.ai:
// The following maps a physical to logical address:
// logical = (physical & 0x1f) + ((physical & 0x3c0) >> 1)
// and logical to physical:
// physical = (logical & 0x1f) + ((logical & 0x1e0) << 1)
const unsigned int otp_logical_addr = 0x1E0;
const unsigned int otp_value = 0x12345678;
unsigned data = 0;

int main(void)
{
  // This call to port_enable() must be made if the application is booted with the XMOS secure boot loader
  port_enable(otp_ports.otp_data_g);

  for (int i = 0; i < 16 * 2; i++)
  {
    otp_read_differential(&otp_ports, otp_logical_addr + i, &data, 1);
    printf("addr = %X, data = %X \n", otp_logical_addr + i, data);
  }

  return 0;
}