Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Improvements to the atsha204 driver #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jrbyrne
Copy link

@jrbyrne jrbyrne commented Jun 17, 2015

I have been working on a design using the ATECC108A chip, and have found the atsha204 driver very useful for communicating with this chip, but encountered a number of issues. I hope you will find these commits to be useful general improvements to the code.

I am not entirely happy with the method used to wake the chip up, as described in the commit comments, but I can't currently think of a better solution.

Note that I have not tested with ATSHA204, only ATECC108A, but these changes should work with both chips.

James Byrne added 4 commits May 29, 2015 11:16
Fix assignment that caused an "initialization from incompatible pointer
type" warning.
This commit makes a number of improvements to the Makefile:

- Test KERNELRELEASE to separate the parts used by kbuild from the parts
used when invoked normally.

- Use standard aliases for $(MAKE) and $(CC) instead of using them
explicitly.

- Separate the building of the test program, give it a proper dependency and
simplify the recipe.

- Add a KOPTIONS variable that can be used to allow cross-compilation.
The call to hwrng_register() can cause an immediate callback to
atsha204_i2c_get_random(). Since the global_chip variable is NULL at this
point, this causes a crash. Fix this by setting global_chip before the call.
The atsha204_i2c_wakeup() function did not work reliably. To wake the chip it
is necessary to hold SDA low for at least tWLO (60us), then delay for tWHI
(500us for ATECC108A; 2.5ms for ATSHA204). There is no way to explicitly hold
the SDA line low in Linux, so instead attempt to send 0 to address 0; this will
hold SDA low for 8 clock cycles (sending the address), which will be more than
60us if the I2C clock speed is less than 133kHz.

The limitation this imposes on the clock speed is restrictive, but this logic
does at least work reliably when the clock speed is under this threshold.

This commit also tidies up the debug so that dev_dbg() is used throughout, and
reorders some of the messages so that they come out in a logical order that
makes debugging easier.
@jbdatko
Copy link
Member

jbdatko commented Jun 18, 2015

Hey this great, thanks! Probably next week I'll have a chance to try it out on the full range of 204a/108a/508 and it should work on all of them.

re: wakeup, I know... it's annoying. On a MCU I disable the i2c controller and then toggle SDA in GPIO mode but yeah, I don't think that can be done (generically) on Linux. There could be a dependency on another module or a callback or something... perhaps...

@jbdatko
Copy link
Member

jbdatko commented Jun 23, 2015

I've merged this but it's on the 0.2 branch at the moment. I've also added some other changes (mainly formatting results from a review I had from a kernel dev).

Once I test the 0.2 branch, I'll move it to master.

Thanks again!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants