Custom OTP modification

The GangFlasher-ST software can program OTP bytes from a file or from a buffer modified programmatically. The following functions can be used to modify the OTP code buffer that is meant to be programmed to the target board, and also to read back the contents of the OTP memory programmed to the target board.

1. F_Put_Byte_to_OTP_Code_Buffer

General Description

Set data value to OTP code buffer. This code buffer will be written to OTP memory of target MPU. The OTP code buffer can be written using the F_AutoProgram command if OTP writing is enabled, or using the F_OTP_Write command if the F_Load_OS or F_AutoProgram commands were previously called.

Syntax

int F_Put_Byte_to_OTP_Code_Buffer(unsigned int addr, unsigned char data);

Input

unsigned int addr : OTP code buffer address, from 0 to 0x17F (inclusive).
unsigned char data : byte to be written to OTP code buffer at specified address.

Output

int : error code

  • ERR_NONE (0) : data successfully entered into code buffer.

  • CODE_OUT_OF_FLASH (0x40) : addr parameter out of range.

See code example below from F_Get_from_OTP_Code_Buffer function.

2. F_Get_Byte_from_OTP_Code_Buffer

General Description

Get data value from OTP code buffer. This code buffer will be written to OTP memory of target MPU. The OTP code buffer can be written using the F_AutoProgram command if OTP writing is enabled, or using the F_OTP_Write command if the F_Load_OS or F_AutoProgram commands were previously called.

Syntax

int F_Get_Byte_from_OTP_Code_Buffer(unsigned int addr, unsigned char &data);

Input

unsigned int addr : OTP code buffer address, from 0 to 0x17F (inclusive).
unsigned char &data : byte from OTP code buffer at specified address.

Output

int : error code

  • ERR_NONE (0) : data read successfully from code buffer.

  • INVALID_ADDR_OR_TYPE (0xFFFFFFFF) : incorrect address, or no data set at specified address.

Example:

int err = ERR_NONE; //1. Initialization err = F_Init(); if (err != ERR_NONE) return err; err = F_LoadTargetConfig("board_setup.cfg"); if (err != ERR_NONE) return err; //Scan for connected boards int dev_count = F_USBAutoScanAndAssign(); if(dev_count <= 0) exit(1);//no USB devices connected //or load preconfigured USB setup //F_LoadUSBConfig("usb_setup.cfg"); //Optionally, pre-load OTP code buffer from file //F_LoadOTPFile("otp.hex"); //2. Print current contents of OTP code bufer for (int i = 0; i < 0x180; i += 0x10) { for (int j = 0; j < 0x10; j++) { unsigned char data = 0; F_Get_Byte_from_OTP_Code_Buffer(i + j, data); printf("0x%x ", data); } printf("\n\r"); } //3. Modify the contents of OTP code buffer for (int i = 0; i < 0x180; i ++) F_Put_Byte_to_OTP_Code_Buffer(i, i); //4. Print modified OTP code buffer data for (int i = 0; i < 0x180; i += 0x10) { for (int j = 0; j < 0x10; j++) { unsigned char data = 0; F_Get_Byte_from_OTP_Code_Buffer(i + j, data); printf("0x%x ", data); } printf("\n\r"); } //5. Load bootloader onto connected boards err = F_Load_OS(); if (err != ERR_NONE) return err; //6. Program OTP code buffer err = F_OTP_Write(); if (err != ERR_NONE) return err;

3. F_Get_Byte_from_OTP_Read_Buffer

General Description

Get OTP data value read back from target 1 to 8 after F_OTP_Read command has been called. For the OTP_Read command to work, the F_Load_OS or F_AutoProgram command needs to be called first.

Syntax

Input

unsigned int addr : OTP read buffer address, from 0 to 0x17F (inclusive).
unsigned char &data : byte from OTP read buffer at specified address, for specified target.
int target : target index from 1 to 8

Output

int : error code

  • ERR_NONE (0) : data read successfully from OTP read buffer

  • INVALID_ADDR_OR_TYPE (0xFFFFFFFF) : incorrect address or target index.

Example