serial number

Technical discussions around xCORE processors (e.g. xcore-200 & xcore.ai).
User avatar
otitov
XCore Addict
Posts: 207
Joined: Thu Dec 10, 2009 11:00 pm
Location: Mexico

serial number

Post by otitov »

I would like to identify each board with unique serial number.

Is it possible to read unique serial number from processor chip? Is it already there?

Should I use OTP memory? In this case - do I need to consider any limitations on OTP use?


User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Thats approach is used in the Ethernet code for the XC-1 :

getmac.c

Code: Select all

void ethernet_getmac_otp(char macaddr[]) 
{
  unsigned int OTPId;
  unsigned int wrd_macaddr[2];
  int value;
  timer tmr;

  value = getMacAddrAux(0, wrd_macaddr);
  if (value == 0) {
    macaddr[0] = (wrd_macaddr[0] >> 8) & 0xFF;
    macaddr[1] = (wrd_macaddr[0]) & 0xFF;
    macaddr[2] = (wrd_macaddr[1] >> 24) & 0xFF;
    macaddr[3] = (wrd_macaddr[1] >> 16) & 0xFF;
    macaddr[4] = (wrd_macaddr[1] >> 8) & 0xFF;
    macaddr[5] = (wrd_macaddr[1]) & 0xFF;
  }
  else {
  // get unique 24bits id from otp, thanks Sam !
    OTPId = ethernet_gethalfmac();
    macaddr[0] = 0x0;
    macaddr[1] = 0x22;
    macaddr[2] = 0x97;
    // reformat that into XMOS mac address and send it out

    if ((OTPId & 0xffffff)==0xffffff) {
      unsigned int time;
      unsigned int a=1664525;
      unsigned int c=1013904223;
      unsigned int j;
      // create a randomish address
      printstr("rand\n");
      tmr :> time;
      j = time & 0xf;
      for (int i=0;i<j;i++)
        time = a * time + c;
      OTPId = time;
    }
    macaddr[3] = (OTPId >> 16) & 0xFF;
    macaddr[4] = (OTPId >> 8) & 0xFF;
    macaddr[5] = OTPId & 0xFF;       
  }
  

  return;
}
extremeRider
Member++
Posts: 19
Joined: Tue Jun 16, 2015 10:50 pm

Post by extremeRider »

Hi,
it it possible to read the serial number from the XK-1A device? (it doesn't have the ethernet port, so no mac address)

Thanks
ffomich
Experienced Member
Posts: 119
Joined: Mon Sep 15, 2014 1:32 pm

Post by ffomich »

Hi,
use can use lib_otpinfo to read serial number and 1 or multiple MAC addresses from OTP memory. There is example there.

To write serial/MACs into OTP use xburn command from command line.
DemoniacMilk
XCore Addict
Posts: 191
Joined: Tue Jul 05, 2016 2:19 pm

Post by DemoniacMilk »

Sorry for reviving an old thread, but in the OTP source code i found a function called otp_board_info_has_serial(), so I assume not all devices have a serial number burnt in?

How do i know if a serial number is available (without having to run a program on the device that uses the function above). If no serial number is available, is there an easy way to have one generated in e.g. the flashing process (so this does not not have to be done manually in software)?