This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

[BUG] CMSIS I2C Driver for STM32F4xx (v2.9)

Hello,

Memory overflow occurs when receiving 2 bytes using the driver.  Works fine for 1 byte.

Here is a code to simulate the problem:

Fullscreen
1
2
3
4
5
6
7
ARM_DRIVER_I2C *I2Cdrv = &Driver_I2C1;
uint8_t buf[2];
uint32_t n;
I2Cdrv->MasterReceive(0x55, buf, 2, false);
osDelay(50);
n = I2Cdrv->GetDataCount(); // n = 544
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I2C_STM32F4xx.c has an I2C Event Interrupt handler (I2C_EV_IRQHandler). Inside of this function there is a code to process such case (when 2 bytes remaining to receive):

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
if (sr1 & I2C_SR1_RXNE) {
/* End master receiver operation */
if ((rx->num == 2U) || (rx->cnt == (rx->num - 2U))) {
/* Two bytes remaining */
if (tr->ctrl & XFER_CTRL_XPENDING) {
i2c->reg->CR2 &= ~I2C_CR2_ITEVTEN;
}
else {
i2c->reg->CR1 |= I2C_CR1_STOP;
}
/* Read data N-1 and N */
rx->data[rx->cnt++] = (uint8_t)i2c->reg->DR;
rx->data[rx->cnt++] = (uint8_t)i2c->reg->DR;
tr->status.busy = 0U;
tr->status.mode = 0U;
i2c->reg->CR1 &= ~I2C_CR1_POS;
if (tr->cb_event) {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

But it never executed. Instead this code (in I2C_EV_IRQHandler) executes again and again, causing memory overflow:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
if (sr1 & I2C_SR1_RXNE) {
/* Master receiver */
rx->data[rx->cnt++] = (uint8_t)i2c->reg->DR;
if (rx->num == 1U) {
/* Single byte transfer completed */
i2c->reg->CR2 &= ~I2C_CR2_ITBUFEN;
if (tr->ctrl & XFER_CTRL_XPENDING) {
i2c->reg->CR2 &= ~I2C_CR2_ITEVTEN;
}
/* (STOP was already sent during ADDR phase) */
tr->status.busy = 0U;
tr->status.mode = 0U;
if (tr->cb_event) {
tr->cb_event (ARM_I2C_EVENT_TRANSFER_DONE);
}
}
else {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

This driver comes with Keil STM32F4xx_DFP v2.14.0.

Best regards,

Eugene

0