Skip to content

Commit b552127

Browse files
authored
Merge pull request #13931 from jeromecoutant/PR_I2C_LEGACY
STM32 I2C: use correct HAL API
2 parents 214291b + b019402 commit b552127

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

targets/TARGET_STM/TARGET_STM32F0/common_objects.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@
4343
extern "C" {
4444
#endif
4545

46+
// temporary workaround
47+
#define HAL_I2C_Master_Seq_Receive_IT HAL_I2C_Master_Sequential_Receive_IT
48+
#define HAL_I2C_Master_Seq_Transmit_IT HAL_I2C_Master_Sequential_Transmit_IT
49+
#define HAL_I2C_Slave_Seq_Receive_IT HAL_I2C_Slave_Sequential_Receive_IT
50+
#define HAL_I2C_Slave_Seq_Transmit_IT HAL_I2C_Slave_Sequential_Transmit_IT
51+
52+
4653
struct pwmout_s {
4754
PWMName pwm;
4855
PinName pin;

targets/TARGET_STM/TARGET_STM32F1/STM32Cube_FW/STM32F1xx_HAL_Driver/stm32f1xx_hal_def.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ extern "C" {
2828

2929
/* Includes ------------------------------------------------------------------*/
3030
#include "stm32f1xx.h"
31-
// #if defined(USE_HAL_LEGACY)
31+
#if defined(USE_HAL_LEGACY)
3232
#include "Legacy/stm32_hal_legacy.h"
33-
// #endif
33+
#endif
3434
#include <stddef.h>
3535

3636
/* Exported types ------------------------------------------------------------*/

targets/TARGET_STM/TARGET_STM32F2/objects.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
extern "C" {
4343
#endif
4444

45+
// temporary workaround
46+
#define HAL_I2C_Master_Seq_Receive_IT HAL_I2C_Master_Sequential_Receive_IT
47+
#define HAL_I2C_Master_Seq_Transmit_IT HAL_I2C_Master_Sequential_Transmit_IT
48+
#define HAL_I2C_Slave_Seq_Receive_IT HAL_I2C_Slave_Sequential_Receive_IT
49+
#define HAL_I2C_Slave_Seq_Transmit_IT HAL_I2C_Slave_Sequential_Transmit_IT
50+
51+
4552
struct gpio_irq_s {
4653
IRQn_Type irq_n;
4754
uint32_t irq_index;

targets/TARGET_STM/TARGET_STM32L1/common_objects.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
extern "C" {
4343
#endif
4444

45+
46+
// temporary workaround
47+
#define HAL_I2C_Master_Seq_Receive_IT HAL_I2C_Master_Sequential_Receive_IT
48+
#define HAL_I2C_Master_Seq_Transmit_IT HAL_I2C_Master_Sequential_Transmit_IT
49+
#define HAL_I2C_Slave_Seq_Receive_IT HAL_I2C_Slave_Sequential_Receive_IT
50+
#define HAL_I2C_Slave_Seq_Transmit_IT HAL_I2C_Slave_Sequential_Transmit_IT
51+
52+
4553
struct pwmout_s {
4654
PWMName pwm;
4755
PinName pin;

targets/TARGET_STM/i2c_api.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
900900
*/
901901
i2c_ev_err_enable(obj, i2c_get_irq_handler(obj));
902902

903-
ret = HAL_I2C_Master_Sequential_Receive_IT(handle, address, (uint8_t *) data, length, obj_s->XferOperation);
903+
ret = HAL_I2C_Master_Seq_Receive_IT(handle, address, (uint8_t *) data, length, obj_s->XferOperation);
904904

905905
if (ret == HAL_OK) {
906906
timeout = BYTE_TIMEOUT_US * (length + 1);
@@ -967,7 +967,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
967967

968968
i2c_ev_err_enable(obj, i2c_get_irq_handler(obj));
969969

970-
ret = HAL_I2C_Master_Sequential_Transmit_IT(handle, address, (uint8_t *) data, length, obj_s->XferOperation);
970+
ret = HAL_I2C_Master_Seq_Transmit_IT(handle, address, (uint8_t *) data, length, obj_s->XferOperation);
971971

972972
if (ret == HAL_OK) {
973973
timeout = BYTE_TIMEOUT_US * (length + 1);
@@ -1015,7 +1015,7 @@ void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)
10151015
}
10161016
#endif
10171017

1018-
HAL_I2C_Master_Sequential_Receive_IT(hi2c, obj_s->address, (uint8_t *)obj->rx_buff.buffer, obj->rx_buff.length, obj_s->XferOperation);
1018+
HAL_I2C_Master_Seq_Receive_IT(hi2c, obj_s->address, (uint8_t *)obj->rx_buff.buffer, obj->rx_buff.length, obj_s->XferOperation);
10191019
} else
10201020
#endif
10211021
{
@@ -1187,7 +1187,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length)
11871187
uint32_t timeout = 0;
11881188

11891189
/* Always use I2C_NEXT_FRAME as slave will just adapt to master requests */
1190-
ret = HAL_I2C_Slave_Sequential_Receive_IT(handle, (uint8_t *) data, length, I2C_NEXT_FRAME);
1190+
ret = HAL_I2C_Slave_Seq_Receive_IT(handle, (uint8_t *) data, length, I2C_NEXT_FRAME);
11911191

11921192
if (ret == HAL_OK) {
11931193
timeout = BYTE_TIMEOUT_US * (length + 1);
@@ -1213,7 +1213,7 @@ int i2c_slave_write(i2c_t *obj, const char *data, int length)
12131213
uint32_t timeout = 0;
12141214

12151215
/* Always use I2C_NEXT_FRAME as slave will just adapt to master requests */
1216-
ret = HAL_I2C_Slave_Sequential_Transmit_IT(handle, (uint8_t *) data, length, I2C_NEXT_FRAME);
1216+
ret = HAL_I2C_Slave_Seq_Transmit_IT(handle, (uint8_t *) data, length, I2C_NEXT_FRAME);
12171217

12181218
if (ret == HAL_OK) {
12191219
timeout = BYTE_TIMEOUT_US * (length + 1);
@@ -1309,10 +1309,10 @@ void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx,
13091309
}
13101310
#endif
13111311
if (tx_length > 0) {
1312-
HAL_I2C_Master_Sequential_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, obj_s->XferOperation);
1312+
HAL_I2C_Master_Seq_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, obj_s->XferOperation);
13131313
}
13141314
if (rx_length > 0) {
1315-
HAL_I2C_Master_Sequential_Receive_IT(handle, address, (uint8_t *)rx, rx_length, obj_s->XferOperation);
1315+
HAL_I2C_Master_Seq_Receive_IT(handle, address, (uint8_t *)rx, rx_length, obj_s->XferOperation);
13161316
}
13171317
} else if (tx_length && rx_length) {
13181318
/* Two steps operation, don't modify XferOperation, keep it for next step */
@@ -1321,13 +1321,13 @@ void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx,
13211321
uint32_t op1 = I2C_FIRST_AND_LAST_FRAME;
13221322
uint32_t op2 = I2C_LAST_FRAME;
13231323
if ((obj_s->XferOperation == op1) || (obj_s->XferOperation == op2)) {
1324-
HAL_I2C_Master_Sequential_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, I2C_FIRST_FRAME);
1324+
HAL_I2C_Master_Seq_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, I2C_FIRST_FRAME);
13251325
} else if ((obj_s->XferOperation == I2C_FIRST_FRAME) ||
13261326
(obj_s->XferOperation == I2C_NEXT_FRAME)) {
1327-
HAL_I2C_Master_Sequential_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, I2C_NEXT_FRAME);
1327+
HAL_I2C_Master_Seq_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, I2C_NEXT_FRAME);
13281328
}
13291329
#elif defined(I2C_IP_VERSION_V2)
1330-
HAL_I2C_Master_Sequential_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, I2C_FIRST_FRAME);
1330+
HAL_I2C_Master_Seq_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, I2C_FIRST_FRAME);
13311331
#endif
13321332
}
13331333
}

0 commit comments

Comments
 (0)