Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is writeConfigSparkFun #18

Open
alberk8 opened this issue Oct 22, 2022 · 5 comments
Open

What is writeConfigSparkFun #18

alberk8 opened this issue Oct 22, 2022 · 5 comments

Comments

@alberk8
Copy link

alberk8 commented Oct 22, 2022

Can someone explain to me what this does and where is the document.

boolean ATECCX08A::writeConfigSparkFun()

@lewispg228
Copy link
Member

Hi @alberk8 ,
There is a high-level description of what the function does just above the function, here:

Writes the necessary configuration settings to the IC in order to work with the SparkFun Arduino Library examples.

Each key slot on this device must be configured properly to allow certain features. Both the keyType and the slotConfig for each slot must be programmed before the config is locked. We are setting up the slot to work as we want for our examples to work. You can read more about all the available settings for each key slot on page 20 of the datasheet here:

https://github.com/sparkfun/SparkFun_Cryptographic_Co-Processor_Breakout_ATECC508A_Qwiic/blob/master/Documentation/datasheet-ATECC508A.pdf

SlotConfig Bits for slots begin at byte 20 of the EEPROM (aka part of the config zone). KeyConfig Bits for slots begin at byte 96 of the EEPROM.

Each bit within each settings byte all work together to get the desired functionality to work. Unfortunately, that leads to quite a bit of jumping around the datasheet and double-checking. Also, you can't really test your settings until the config is locked, so that means if you get them incorrect, then that IC is no longer functional. So, unfortunately, until you gain lots of experience with this IC, it means that it is fairly difficult to avoid bricking at least one or two ICs during new configuration experimenting.

If you are interested in setting up the IC to do other features outside of our examples, then I'd like to suggest you reach out to the forum to see if there are any other users doing something similar.

Hope this helps,
Pete

@alberk8
Copy link
Author

alberk8 commented Oct 25, 2022

Thank you for the reply. What I don't understand for example is SlotConfig, where the (20 is divided by 4) result2 = write(ZONE_CONFIG, (20 / 4), data2, 4);

@lewispg228
Copy link
Member

There is a lot of information about address encoding on page 58 of the datasheet (section 9.1.4). But basically, the slots/blocks/word-offsets are designed in a way that makes it efficient to create the actual word address you need to send. (Specifically, the fact that data is accessed on a 4 byte word boundary). Without going into all the actual steps needed to create the necessary param2 address, you can simply take the desired address and drop the least significant two bits. (This can be accomplished by dividing by 4).

image

Note, address encoding is different for the config/otp zones vs the data zone. Because we are working within the config zone for these writes, we are able to divide by four and the address byte is "scooted" over (dropping least sig two bits) to indicate the necessary block and offset:

image

Byte 20 is B0001 0100.

divide by 4 and you get:

B0000 0101

Bits [4:3] are our block: 0
Bits [2:0] are our offset: 5

Byte 96 is B0110 0000

divide by 4 and you get:

B 0001 1000

Bits [4:3] are our block: 3
Bits [2:0] are our offset: 0

Hope this helps!
Pete

@alberk8
Copy link
Author

alberk8 commented Oct 27, 2022

Thank you. This is a fantastic and clear explanation.

@alberk8 alberk8 closed this as completed Oct 27, 2022
@alberk8
Copy link
Author

alberk8 commented Oct 27, 2022

The specs says writing/reading is 4 or 32 bytes. when writing to the 4 bytes operation (slot config). which of the 2 bytes are of significant (the 2 MSB or 2 LSB) ?.

@alberk8 alberk8 reopened this Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants