-
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
stm32l1/i2c: initial update for the i2c peripheral driver #4727
stm32l1/i2c: initial update for the i2c peripheral driver #4727
Conversation
@PeterKietzmann Here is the PR about the i2c driver we talkt about offline. |
@@ -139,37 +139,27 @@ static const timer_conf_t timer_config[] = { | |||
#define I2C_IRQ_PRIO 1 | |||
#define I2C_APBCLK (36000000U) | |||
|
|||
static const i2c_conf_t i2c_config[] = { | |||
/* device, port, scl-, sda-pin-number, scl-, sda-AF, ER-IRQn, EV-IRQn */ | |||
{I2C1, GPIOB, 8, 9, 4, 4, I2C1_ER_IRQn, I2C1_EV_IRQn}, |
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.
Please initialize all pins with the pin generator macro to be independent of the port.
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.
Ah and nearly forgot: there are also mux types defined there. Please use them
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.
@PeterKietzmann Done. But how to extract the pin and port number in the i2c driver? using the gpio api?
Edit: I see in the lower comments it happens via the gpio api.
@ReneHerthel thanks for your work. Please try to address my comments and/or answer my questions. I know you just try to improve the driver but now that you are at it, we can try to optimize a bit more ;-) ! |
I2C_TypeDef *i2c; | ||
GPIO_TypeDef *port; | ||
int pin_scl = 0, pin_sda = 0; | ||
I2C_TypeDef *i2c = i2c_config[dev].dev; |
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.
This means that if dev
is larger than the defined elements we are going to access someone else's memory and it's going to be fun to debug... I think the old behaviour (verification) makes more sense for a general purpose driver
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.
@lebrush what do you mean byold behaviour (verification)? Do you mean if (dev >= I2C_NUMOF)
?
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.
yes :-)
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.
@ReneHerthel please put this check in again. We already discussed it some comments ago.
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.
@PeterKietzmann It's already done.
Edit: or did you mean in the init_master function?? Then we should put it in all functions, where the i2c_config[dev].
is used.
In the original code, there were only the switch-cases..
The "if (dev >= I2C_NUMOF)
" are only in the acquire and release functions.
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.
Please include it in all functions.
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.
@PeterKietzmann Check.
Sorry for commenting in that commit. Wasn't aware of it :/ |
@PeterKietzmann Should I wait for the merge of the PR with the open drain you mentioned? |
break; | ||
#endif | ||
} | ||
RCC->APB1ENR |= (RCC_APB1ENR_I2C1EN << dev); |
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.
That was what I (generally) meant with removing the CLK enabling macros in the periph_conf - yes. But are you sure that this piece of code does what you expect? I'm not but I didn't check in detail
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.
@PeterKietzmann Hmm here is something similiar to this.
It uses the I2C-Enabling-Mask by left shifting it by the value of dev.
My thought:
RCC_APB1ENR_I2C1EN
:= 0x00200000 := 0000 0000 0010 0000 .... and
RCC_APB1ENR_I2C2EN
:= 0x00400000 := 0000 0000 0100 0000 ....
(see: stm32l1xx.h)
for dev = 0 it's the first one AND
for dev = 1 it's the second one by shifting RCC_APB1ENR_I2C1EN to left by1.
If you have another idea how to do this better, please tell me :)
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.
Actually I was confused about dev
but that was my bad. Seems reasonable.
8d5aebc
to
e0763be
Compare
Rebased |
e0763be
to
2d2571c
Compare
Squashed |
2d2571c
to
4a4b3f6
Compare
@haukepetersen Travis fails IMO unrelated to this PR.
IIRC you did something with the nrf51 recently. Any ideas how to proceed? |
Forget about it, the build error seemed to be unrelated as we now have green lights. This change will need adaption to #4472 once a decision was found. We successfully tested both I2C ports with tests/driver_srf02 as well as with tests/periph_i2c (and the srf02 connected). Will merge now because we need this enhancement for further developments. ACK and go |
stm32l1/i2c: initial update for the i2c peripheral driver
This PR is needed for testing the limifrog-v1 drivers.