Skip to content

Commit

Permalink
Check initial state before running hello_otp example
Browse files Browse the repository at this point in the history
  • Loading branch information
will-v-pi committed Sep 27, 2024
1 parent 362f676 commit b0f766f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions otp/hello_otp/hello_otp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ int main() {
// Row to write raw data
uint16_t raw_row = 0x410;

// Check rows are empty - else the rest of the tests won't behave as expected
unsigned char initial_data[32] = {0};
cmd.flags = ecc_row;
ret = rom_func_otp_access(initial_data, sizeof(initial_data)/2, cmd);
if (ret) {
printf("ERROR: Initial ECC Row Read failed with error %d\n", ret);
}
cmd.flags = raw_row;
ret = rom_func_otp_access(initial_data+(sizeof(initial_data)/2), sizeof(initial_data)/2, cmd);
if (ret) {
printf("ERROR: Initial Raw Row Read failed with error %d\n", ret);
}
for (int i=0; i < sizeof(initial_data); i++) {
if (initial_data[i] != 0) {
printf("ERROR: This example requires empty OTP rows to run - change the ecc_row and raw_row variables to an empty row and recompile\n");
return 0;
}
}

if (ecc_row) {
// Write an ECC value to OTP - the buffer must have a multiple of 2 length for ECC data
unsigned char ecc_write_data[16] = "Hello from OTP";
Expand Down

0 comments on commit b0f766f

Please sign in to comment.