Skip to content

Commit

Permalink
Merge pull request #13931 from jeromecoutant/PR_I2C_LEGACY
Browse files Browse the repository at this point in the history
STM32 I2C: use correct HAL API
  • Loading branch information
0xc0170 authored Nov 24, 2020
2 parents 214291b + b019402 commit b552127
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
7 changes: 7 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F0/common_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
extern "C" {
#endif

// temporary workaround
#define HAL_I2C_Master_Seq_Receive_IT HAL_I2C_Master_Sequential_Receive_IT
#define HAL_I2C_Master_Seq_Transmit_IT HAL_I2C_Master_Sequential_Transmit_IT
#define HAL_I2C_Slave_Seq_Receive_IT HAL_I2C_Slave_Sequential_Receive_IT
#define HAL_I2C_Slave_Seq_Transmit_IT HAL_I2C_Slave_Sequential_Transmit_IT


struct pwmout_s {
PWMName pwm;
PinName pin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ extern "C" {

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx.h"
// #if defined(USE_HAL_LEGACY)
#if defined(USE_HAL_LEGACY)
#include "Legacy/stm32_hal_legacy.h"
// #endif
#endif
#include <stddef.h>

/* Exported types ------------------------------------------------------------*/
Expand Down
7 changes: 7 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F2/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
extern "C" {
#endif

// temporary workaround
#define HAL_I2C_Master_Seq_Receive_IT HAL_I2C_Master_Sequential_Receive_IT
#define HAL_I2C_Master_Seq_Transmit_IT HAL_I2C_Master_Sequential_Transmit_IT
#define HAL_I2C_Slave_Seq_Receive_IT HAL_I2C_Slave_Sequential_Receive_IT
#define HAL_I2C_Slave_Seq_Transmit_IT HAL_I2C_Slave_Sequential_Transmit_IT


struct gpio_irq_s {
IRQn_Type irq_n;
uint32_t irq_index;
Expand Down
8 changes: 8 additions & 0 deletions targets/TARGET_STM/TARGET_STM32L1/common_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
extern "C" {
#endif


// temporary workaround
#define HAL_I2C_Master_Seq_Receive_IT HAL_I2C_Master_Sequential_Receive_IT
#define HAL_I2C_Master_Seq_Transmit_IT HAL_I2C_Master_Sequential_Transmit_IT
#define HAL_I2C_Slave_Seq_Receive_IT HAL_I2C_Slave_Sequential_Receive_IT
#define HAL_I2C_Slave_Seq_Transmit_IT HAL_I2C_Slave_Sequential_Transmit_IT


struct pwmout_s {
PWMName pwm;
PinName pin;
Expand Down
20 changes: 10 additions & 10 deletions targets/TARGET_STM/i2c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
*/
i2c_ev_err_enable(obj, i2c_get_irq_handler(obj));

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

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

i2c_ev_err_enable(obj, i2c_get_irq_handler(obj));

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

if (ret == HAL_OK) {
timeout = BYTE_TIMEOUT_US * (length + 1);
Expand Down Expand Up @@ -1015,7 +1015,7 @@ void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)
}
#endif

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

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

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

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

if (ret == HAL_OK) {
timeout = BYTE_TIMEOUT_US * (length + 1);
Expand Down Expand Up @@ -1309,10 +1309,10 @@ void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx,
}
#endif
if (tx_length > 0) {
HAL_I2C_Master_Sequential_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, obj_s->XferOperation);
HAL_I2C_Master_Seq_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, obj_s->XferOperation);
}
if (rx_length > 0) {
HAL_I2C_Master_Sequential_Receive_IT(handle, address, (uint8_t *)rx, rx_length, obj_s->XferOperation);
HAL_I2C_Master_Seq_Receive_IT(handle, address, (uint8_t *)rx, rx_length, obj_s->XferOperation);
}
} else if (tx_length && rx_length) {
/* Two steps operation, don't modify XferOperation, keep it for next step */
Expand All @@ -1321,13 +1321,13 @@ void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx,
uint32_t op1 = I2C_FIRST_AND_LAST_FRAME;
uint32_t op2 = I2C_LAST_FRAME;
if ((obj_s->XferOperation == op1) || (obj_s->XferOperation == op2)) {
HAL_I2C_Master_Sequential_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, I2C_FIRST_FRAME);
HAL_I2C_Master_Seq_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, I2C_FIRST_FRAME);
} else if ((obj_s->XferOperation == I2C_FIRST_FRAME) ||
(obj_s->XferOperation == I2C_NEXT_FRAME)) {
HAL_I2C_Master_Sequential_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, I2C_NEXT_FRAME);
HAL_I2C_Master_Seq_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, I2C_NEXT_FRAME);
}
#elif defined(I2C_IP_VERSION_V2)
HAL_I2C_Master_Sequential_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, I2C_FIRST_FRAME);
HAL_I2C_Master_Seq_Transmit_IT(handle, address, (uint8_t *)tx, tx_length, I2C_FIRST_FRAME);
#endif
}
}
Expand Down

0 comments on commit b552127

Please sign in to comment.