-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Driver for AT24CXXX EEPROM #11929
Driver for AT24CXXX EEPROM #11929
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can make the driver much simpler by using some existing i2c helper functions.
45e89f2
to
aa7e32f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw: If you want to fix a bug in commit with ID , instead of normal commit you can use git commit --fixup=<FOO>
. When later the reviewer asks to squash, you can then use git commit --autosquash -i <COMMIT_ID>
and git will sort the fixup-commit to be integrated into the commits they fix. This can safe you some work, but has the disadvantage that the commit messages of the fixes no longer make sense. (But eventually those commits will be integrated into the one they fix anyway.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two remarks from me, see inline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pointed out some minor issues inline.
This is by the way a very nice PR, especially since it is your first :-)
I have just seen that there are many different at24xxx. They also vary in page size, so I am going to add the page size to the configuration parameters. |
To me it would also be fine to limit this PR to a subset of devices with the same page size. The AT24C256 and the AT24C128 are the most popular ones anyway, so maybe no one will ever need support for the other chips. In any case, I'm personally a fan of limiting the problem space a PR wants to solve, so that reviewing is easier: Support for more device could be added in a follow-up PR. |
Oh, almost forgot: Could you add (Or maybe even Edit: Here is a backup of the old AT24C256 data sheet, here is the new AT24C256C version on the official Microchip Homepage. The wildcard in |
@benpicco: I only just read your comment. Do you still prefer |
@maribu I'm fine with either. All devices in the kernel follow the AT24Cxxx naming scheme too. Linux also has handling for devices with multiple addresses but I agree that this is out of the scope of this PR since I assume neither of us has the hardware to test this. |
OK. One last thing came to my mind: The indentation is different from RIOT's standard. You can use the command line tool |
09297d7
to
4227796
Compare
@fabian18: When I test with no device connected to the I2C bus, it seems the test/driver hangs instead of returning with an error code. Can you reproduce that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See inline comments. I'm not fully sure how to do proper error handling. Maybe it is the best to give up on having the API compatible with the EEPROM API for now, as the API prevents any reasonable error handling :-/
@maribu |
Thank you for the update! Good to have extended device support.
at24mac.patchdiff --git a/drivers/Makefile.dep b/drivers/Makefile.dep
index 423319b245..0b60b0e52c 100644
--- a/drivers/Makefile.dep
+++ b/drivers/Makefile.dep
@@ -36,16 +36,12 @@ ifneq (,$(filter at,$(USEMODULE)))
USEMODULE += isrpipe_read_timeout
endif
-ifneq (,$(filter at24c%,$(USEMODULE)))
+ifneq (,$(filter at24mac at24c%,$(USEMODULE)))
FEATURES_REQUIRED += periph_i2c
USEMODULE += xtimer
USEMODULE += at24cxxx
endif
-ifneq (,$(filter at24mac,$(USEMODULE)))
- FEATURES_REQUIRED += periph_i2c
-endif
-
ifneq (,$(filter at30tse75x,$(USEMODULE)))
USEMODULE += xtimer
FEATURES_REQUIRED += periph_i2c
diff --git a/drivers/at24cxxx/include/at24cxxx_defines.h b/drivers/at24cxxx/include/at24cxxx_defines.h
index 312ba9d50d..4d2c0e715a 100644
--- a/drivers/at24cxxx/include/at24cxxx_defines.h
+++ b/drivers/at24cxxx/include/at24cxxx_defines.h
@@ -299,6 +299,29 @@ extern "C" {
/ AT24CXXX_POLL_DELAY_US))
/** @} */
+/**
+ * @name AT24MAC402/602 constants
+ * @{
+ */
+/**
+ * @brief 2048 byte memory
+ */
+#define AT24MAC_EEPROM_SIZE (2048U)
+/**
+ * @brief 256 pages of 8 bytes
+ */
+#define AT24MAC_PAGE_SIZE (8U)
+/**
+ * @brief Delay to complete write operation
+ */
+#define AT24MAC_PAGE_WRITE_DELAY_US (5000U)
+/**
+ * @brief Number of poll attempts
+ */
+#define AT24MAC_MAX_POLLS (1 + (AT24MAC_PAGE_WRITE_DELAY_US \
+ / AT24CXXX_POLL_DELAY_US))
+/** @} */
+
/**
* @name Set constants depending on module
* @{
@@ -347,6 +370,10 @@ extern "C" {
#define AT24CXXX_EEPROM_SIZE (AT24C01A_EEPROM_SIZE)
#define AT24CXXX_PAGE_SIZE (AT24C01A_PAGE_SIZE)
#define AT24CXXX_MAX_POLLS (AT24C01A_MAX_POLLS)
+#elif IS_USED(MODULE_AT24MAC)
+#define AT24CXXX_EEPROM_SIZE (AT24MAC_EEPROM_SIZE)
+#define AT24CXXX_PAGE_SIZE (AT24MAC_PAGE_SIZE)
+#define AT24CXXX_MAX_POLLS (AT24MAC_MAX_POLLS)
#else /* minimal */
#define AT24CXXX_EEPROM_SIZE (128U) /**< EEPROM size */
#define AT24CXXX_PAGE_SIZE (4U) /**< page size */ same54-xpro.patchdiff --git a/boards/same54-xpro/include/board.h b/boards/same54-xpro/include/board.h
index cde35f1a69..a80f6ebde3 100644
--- a/boards/same54-xpro/include/board.h
+++ b/boards/same54-xpro/include/board.h
@@ -33,6 +33,7 @@ extern "C" {
#define AT24MAC_PARAM_I2C_DEV I2C_DEV(0)
#define AT24MAC_PARAM_I2C_ADDR (0x5E)
#define AT24MAC_PARAM_TYPE AT24MAC4XX
+#define AT24CXXX_PARAM_ADDR (0x56)
/** @} */
/** |
The So maybe try: /**
* @name AT24MAC402/602 constants
* @{
*/
/**
* @brief 256 byte memory
*/
#define AT24MAC_EEPROM_SIZE (256U)
/**
* @brief 16 pages of 16 bytes
*/
#define AT24MAC_PAGE_SIZE (16U)
/**
* @brief Delay to complete write operation
*/
#define AT24MAC_PAGE_WRITE_DELAY_US (5000U)
/**
* @brief Number of poll attempts
*/
#define AT24MAC_MAX_POLLS (1 + (AT24MAC_PAGE_WRITE_DELAY_US \
/ AT24CXXX_POLL_DELAY_US))
/** @} */ And change the positions in the test so that you stay in the memory range. |
Should I make the positions in the tests configurable too? #ifndef WRITE_POSITION
#define WRITE_POSITION (444U)
#endif |
You are of course right! Now with that and
No - we know the parameters of the EEPROM at compile time, so select some good values for testing, e.g. #define WRITE_POSITION (AT24CXXX_EEPROM_SIZE - 3 * AT24CXXX_PAGE_SIZE - 4) will make sure that we always test writing over the page boundary. |
@benpicco Could you please test again? Then I can squash, make Murdock green and maybe we can finally finish this? |
Tried it again, works as expected - please squash. same54-xpro with at24mac
|
c4d65c9
to
11f8c05
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good and works.
We can adapt this to the common EEPROM API later - and finalizing the API might be easier with some existing code to make use of it.
Mind giving #11945 a look? |
I will look at #11945 but I cannot test because I don´t have an SPI EEPROM. |
What´s wrong with Murdock?: |
11f8c05
to
07f7d81
Compare
Pausing for #13456 |
Thank you @benpicco |
Contribution description
This contribution adds a driver to support the external EEPROM modules
AT24C128 and ATC256.
It allows integration with the existing EEPROM registry, while it includes
a pseudomodule that provides wrappers for the expected EEPROM API.
Testing procedure
Development and testing has been done with the bluepill board.
There is a test application in tests/driver_at24cxxx.
You can also run the existing test for the EEPROM registry.
USEMODULE=at24cxxx_eepreg_wrapper make BOARD=bluepill flash
make BOARD=bluepill term
Issues/PRs references
None