Other Parts Discussed in Thread: C2000WARE
Tool/software:
I could not find a direct example to program the OTP passwords. Could you please review the code below and tell if it is the recommended approach?
Linker command file:
MEMORY
{
OTP_MEMORY : origin = 0x78000, length = 0x00020
}
SECTIONS
{
.otpData : > OTP_MEMORY, PAGE = 0
}
Note: Replace 0x78000 and 0x00020 with the appropriate start address and length for your specific OTP region as defined in the TMS320F28P55 datasheet.
Main.c
#pragma DATA_SECTION(otpData, ".otpData");
const uint32_t otpData[4] = {0x12345678, 0x9ABCDEF0, 0x0FEDCBA9, 0x87654321};
#include "Fapi_UserDefinedFunctions.h"
#include "F021_F28004x_C28x.h"
void programOTP(void)
{
Fapi_StatusType status;
uint32_t otpAddress = 0x78000; // Starting address of OTP
uint32_t dataBuffer[4] = {0x12345678, 0x9ABCDEF0, 0x0FEDCBA9, 0x87654321}; // enter your own passwords
// Initialize the Flash API
status = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 200); // 200 MHz system clock
if (status != Fapi_Status_Success)
{
// Handle error
}
// Set active Flash bank
status = Fapi_setActiveFlashBank(Fapi_FlashBank0);
if (status != Fapi_Status_Success)
{
// Handle error
}
// Program the OTP
status = Fapi_issueProgrammingCommand((uint32_t *)otpAddress, dataBuffer, 4, 0, 0, Fapi_AutoEccGeneration);
if (status != Fapi_Status_Success)
{
// Handle error
}
// Wait for the program operation to complete
while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady);
// Verify the programmed data
for (uint16_t i = 0; i < 4; i++)
{
if (*(volatile uint32_t *)(otpAddress + (i * 4)) != dataBuffer[i])
{
// Handle verification error
}
}
}