Skip to content

Commit 35bf526

Browse files
committed
STM32: Remove IAR compilation warning
1 parent ad55bc2 commit 35bf526

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

targets/TARGET_STM/i2c_api.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,10 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
725725
int count = I2C_ERROR_BUS_BUSY, ret = 0;
726726
uint32_t timeout = 0;
727727

728-
if ((obj_s->XferOperation == I2C_FIRST_AND_LAST_FRAME) ||
729-
(obj_s->XferOperation == I2C_LAST_FRAME)) {
728+
// Trick to remove compiler warning "left and right operands are identical" in some cases
729+
uint32_t op1 = I2C_FIRST_AND_LAST_FRAME;
730+
uint32_t op2 = I2C_LAST_FRAME;
731+
if ((obj_s->XferOperation == op1) || (obj_s->XferOperation == op2)) {
730732
if (stop)
731733
obj_s->XferOperation = I2C_FIRST_AND_LAST_FRAME;
732734
else
@@ -777,8 +779,10 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
777779
int count = I2C_ERROR_BUS_BUSY, ret = 0;
778780
uint32_t timeout = 0;
779781

780-
if ((obj_s->XferOperation == I2C_FIRST_AND_LAST_FRAME) ||
781-
(obj_s->XferOperation == I2C_LAST_FRAME)) {
782+
// Trick to remove compiler warning "left and right operands are identical" in some cases
783+
uint32_t op1 = I2C_FIRST_AND_LAST_FRAME;
784+
uint32_t op2 = I2C_LAST_FRAME;
785+
if ((obj_s->XferOperation == op1) || (obj_s->XferOperation == op2)) {
782786
if (stop)
783787
obj_s->XferOperation = I2C_FIRST_AND_LAST_FRAME;
784788
else
@@ -1065,8 +1069,10 @@ void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx,
10651069

10661070
/* Set operation step depending if stop sending required or not */
10671071
if ((tx_length && !rx_length) || (!tx_length && rx_length)) {
1068-
if ((obj_s->XferOperation == I2C_FIRST_AND_LAST_FRAME) ||
1069-
(obj_s->XferOperation == I2C_LAST_FRAME)) {
1072+
// Trick to remove compiler warning "left and right operands are identical" in some cases
1073+
uint32_t op1 = I2C_FIRST_AND_LAST_FRAME;
1074+
uint32_t op2 = I2C_LAST_FRAME;
1075+
if ((obj_s->XferOperation == op1) || (obj_s->XferOperation == op2)) {
10701076
if (stop)
10711077
obj_s->XferOperation = I2C_FIRST_AND_LAST_FRAME;
10721078
else
@@ -1088,8 +1094,10 @@ void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx,
10881094
}
10891095
else if (tx_length && rx_length) {
10901096
/* Two steps operation, don't modify XferOperation, keep it for next step */
1091-
if ((obj_s->XferOperation == I2C_FIRST_AND_LAST_FRAME) ||
1092-
(obj_s->XferOperation == I2C_LAST_FRAME)) {
1097+
// Trick to remove compiler warning "left and right operands are identical" in some cases
1098+
uint32_t op1 = I2C_FIRST_AND_LAST_FRAME;
1099+
uint32_t op2 = I2C_LAST_FRAME;
1100+
if ((obj_s->XferOperation == op1) || (obj_s->XferOperation == op2)) {
10931101
HAL_I2C_Master_Sequential_Transmit_IT(handle, address, (uint8_t*)tx, tx_length, I2C_FIRST_FRAME);
10941102
} else if ((obj_s->XferOperation == I2C_FIRST_FRAME) ||
10951103
(obj_s->XferOperation == I2C_NEXT_FRAME)) {

0 commit comments

Comments
 (0)