Skip to content

Commit 9021fdd

Browse files
authored
Check initial state before running hello_otp example (#555)
1 parent 362f676 commit 9021fdd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

otp/hello_otp/hello_otp.c

+19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ int main() {
2020
// Row to write raw data
2121
uint16_t raw_row = 0x410;
2222

23+
// Check rows are empty - else the rest of the tests won't behave as expected
24+
unsigned char initial_data[32] = {0};
25+
cmd.flags = ecc_row;
26+
ret = rom_func_otp_access(initial_data, sizeof(initial_data)/2, cmd);
27+
if (ret) {
28+
printf("ERROR: Initial ECC Row Read failed with error %d\n", ret);
29+
}
30+
cmd.flags = raw_row;
31+
ret = rom_func_otp_access(initial_data+(sizeof(initial_data)/2), sizeof(initial_data)/2, cmd);
32+
if (ret) {
33+
printf("ERROR: Initial Raw Row Read failed with error %d\n", ret);
34+
}
35+
for (int i=0; i < sizeof(initial_data); i++) {
36+
if (initial_data[i] != 0) {
37+
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");
38+
return 0;
39+
}
40+
}
41+
2342
if (ecc_row) {
2443
// Write an ECC value to OTP - the buffer must have a multiple of 2 length for ECC data
2544
unsigned char ecc_write_data[16] = "Hello from OTP";

0 commit comments

Comments
 (0)