Skip to content

Commit 23926a2

Browse files
committed
[STM32] HAL I2C (V2) sequential transmit / receive
In case of sequential transmit / receive, there is a need to: - not use the reload option - generate a new START on each new transaction This applies to all HAL supporting the IP version V2.
1 parent a0722b1 commit 23926a2

File tree

5 files changed

+10
-82
lines changed

5 files changed

+10
-82
lines changed

targets/TARGET_STM/TARGET_STM32F0/device/stm32f0xx_hal_i2c.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,7 +2585,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
25852585
/* Prepare transfer parameters */
25862586
hi2c->pBuffPtr = pData;
25872587
hi2c->XferCount = Size;
2588-
hi2c->XferOptions = XferOptions;
2588+
hi2c->XferOptions = (XferOptions & (~I2C_RELOAD_MODE));
25892589
hi2c->XferISR = I2C_Master_ISR_IT;
25902590

25912591
/* If size > MAX_NBYTE_SIZE, use reload mode */
@@ -2598,15 +2598,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
25982598
{
25992599
hi2c->XferSize = hi2c->XferCount;
26002600
xfermode = hi2c->XferOptions;
2601-
2602-
/* If transfer direction not change, do not generate Restart Condition */
2603-
/* Mean Previous state is same as current state */
2604-
if(hi2c->PreviousState == I2C_STATE_SLAVE_BUSY_TX)
2605-
{
2606-
xferrequest = I2C_NO_STARTSTOP;
2607-
}
26082601
}
2609-
26102602

26112603
/* Send Slave Address and set NBYTES to write */
26122604
I2C_TransferConfig(hi2c, DevAddress, hi2c->XferSize, xfermode, xferrequest);
@@ -2659,7 +2651,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c,
26592651
/* Prepare transfer parameters */
26602652
hi2c->pBuffPtr = pData;
26612653
hi2c->XferCount = Size;
2662-
hi2c->XferOptions = XferOptions;
2654+
hi2c->XferOptions = (XferOptions & (~I2C_RELOAD_MODE));
26632655
hi2c->XferISR = I2C_Master_ISR_IT;
26642656

26652657
/* If hi2c->XferCount > MAX_NBYTE_SIZE, use reload mode */
@@ -2672,13 +2664,6 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c,
26722664
{
26732665
hi2c->XferSize = hi2c->XferCount;
26742666
xfermode = hi2c->XferOptions;
2675-
2676-
/* If transfer direction not change, do not generate Restart Condition */
2677-
/* Mean Previous state is same as current state */
2678-
if(hi2c->PreviousState == I2C_STATE_MASTER_BUSY_RX)
2679-
{
2680-
xferrequest = I2C_NO_STARTSTOP;
2681-
}
26822667
}
26832668

26842669
/* Send Slave Address and set NBYTES to read */

targets/TARGET_STM/TARGET_STM32F3/device/stm32f3xx_hal_i2c.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,7 +2583,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
25832583
/* Prepare transfer parameters */
25842584
hi2c->pBuffPtr = pData;
25852585
hi2c->XferCount = Size;
2586-
hi2c->XferOptions = XferOptions;
2586+
hi2c->XferOptions = (XferOptions & (~I2C_RELOAD_MODE));
25872587
hi2c->XferISR = I2C_Master_ISR_IT;
25882588

25892589
/* If size > MAX_NBYTE_SIZE, use reload mode */
@@ -2596,13 +2596,6 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
25962596
{
25972597
hi2c->XferSize = hi2c->XferCount;
25982598
xfermode = hi2c->XferOptions;
2599-
2600-
/* If transfer direction not change, do not generate Restart Condition */
2601-
/* Mean Previous state is same as current state */
2602-
if(hi2c->PreviousState == I2C_STATE_SLAVE_BUSY_TX)
2603-
{
2604-
xferrequest = I2C_NO_STARTSTOP;
2605-
}
26062599
}
26072600

26082601

@@ -2657,7 +2650,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c,
26572650
/* Prepare transfer parameters */
26582651
hi2c->pBuffPtr = pData;
26592652
hi2c->XferCount = Size;
2660-
hi2c->XferOptions = XferOptions;
2653+
hi2c->XferOptions = (XferOptions & (~I2C_RELOAD_MODE));
26612654
hi2c->XferISR = I2C_Master_ISR_IT;
26622655

26632656
/* If hi2c->XferCount > MAX_NBYTE_SIZE, use reload mode */
@@ -2670,13 +2663,6 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c,
26702663
{
26712664
hi2c->XferSize = hi2c->XferCount;
26722665
xfermode = hi2c->XferOptions;
2673-
2674-
/* If transfer direction not change, do not generate Restart Condition */
2675-
/* Mean Previous state is same as current state */
2676-
if(hi2c->PreviousState == I2C_STATE_MASTER_BUSY_RX)
2677-
{
2678-
xferrequest = I2C_NO_STARTSTOP;
2679-
}
26802666
}
26812667

26822668
/* Send Slave Address and set NBYTES to read */

targets/TARGET_STM/TARGET_STM32F7/device/stm32f7xx_hal_i2c.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
25362536
/* Prepare transfer parameters */
25372537
hi2c->pBuffPtr = pData;
25382538
hi2c->XferCount = Size;
2539-
hi2c->XferOptions = XferOptions;
2539+
hi2c->XferOptions = (XferOptions & (~I2C_RELOAD_MODE));
25402540
hi2c->XferISR = I2C_Master_ISR_IT;
25412541

25422542
/* If size > MAX_NBYTE_SIZE, use reload mode */
@@ -2549,13 +2549,6 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
25492549
{
25502550
hi2c->XferSize = hi2c->XferCount;
25512551
xfermode = hi2c->XferOptions;
2552-
2553-
/* If transfer direction not change, do not generate Restart Condition */
2554-
/* Mean Previous state is same as current state */
2555-
if(hi2c->PreviousState == I2C_STATE_SLAVE_BUSY_TX)
2556-
{
2557-
xferrequest = I2C_NO_STARTSTOP;
2558-
}
25592552
}
25602553

25612554
/* Send Slave Address and set NBYTES to write */
@@ -2608,7 +2601,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c,
26082601
/* Prepare transfer parameters */
26092602
hi2c->pBuffPtr = pData;
26102603
hi2c->XferCount = Size;
2611-
hi2c->XferOptions = XferOptions;
2604+
hi2c->XferOptions = (XferOptions & (~I2C_RELOAD_MODE));
26122605
hi2c->XferISR = I2C_Master_ISR_IT;
26132606

26142607
/* If hi2c->XferCount > MAX_NBYTE_SIZE, use reload mode */
@@ -2621,13 +2614,6 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c,
26212614
{
26222615
hi2c->XferSize = hi2c->XferCount;
26232616
xfermode = hi2c->XferOptions;
2624-
2625-
/* If transfer direction not change, do not generate Restart Condition */
2626-
/* Mean Previous state is same as current state */
2627-
if(hi2c->PreviousState == I2C_STATE_MASTER_BUSY_RX)
2628-
{
2629-
xferrequest = I2C_NO_STARTSTOP;
2630-
}
26312617
}
26322618

26332619
/* Send Slave Address and set NBYTES to read */

targets/TARGET_STM/TARGET_STM32L0/device/stm32l0xx_hal_i2c.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
25912591
/* Prepare transfer parameters */
25922592
hi2c->pBuffPtr = pData;
25932593
hi2c->XferCount = Size;
2594-
hi2c->XferOptions = XferOptions;
2594+
hi2c->XferOptions = (XferOptions & (~I2C_RELOAD_MODE));
25952595
hi2c->XferISR = I2C_Master_ISR_IT;
25962596

25972597
/* If size > MAX_NBYTE_SIZE, use reload mode */
@@ -2606,13 +2606,6 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
26062606
xfermode = hi2c->XferOptions;
26072607
}
26082608

2609-
/* If transfer direction not change, do not generate Restart Condition */
2610-
/* Mean Previous state is same as current state */
2611-
if(hi2c->PreviousState == I2C_STATE_MASTER_BUSY_TX)
2612-
{
2613-
xferrequest = I2C_NO_STARTSTOP;
2614-
}
2615-
26162609
/* Send Slave Address and set NBYTES to write */
26172610
I2C_TransferConfig(hi2c, DevAddress, hi2c->XferSize, xfermode, xferrequest);
26182611

@@ -2664,7 +2657,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c,
26642657
/* Prepare transfer parameters */
26652658
hi2c->pBuffPtr = pData;
26662659
hi2c->XferCount = Size;
2667-
hi2c->XferOptions = XferOptions;
2660+
hi2c->XferOptions = (XferOptions & (~I2C_RELOAD_MODE));
26682661
hi2c->XferISR = I2C_Master_ISR_IT;
26692662

26702663
/* If hi2c->XferCount > MAX_NBYTE_SIZE, use reload mode */
@@ -2679,13 +2672,6 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c,
26792672
xfermode = hi2c->XferOptions;
26802673
}
26812674

2682-
/* If transfer direction not change, do not generate Restart Condition */
2683-
/* Mean Previous state is same as current state */
2684-
if(hi2c->PreviousState == I2C_STATE_MASTER_BUSY_RX)
2685-
{
2686-
xferrequest = I2C_NO_STARTSTOP;
2687-
}
2688-
26892675
/* Send Slave Address and set NBYTES to read */
26902676
I2C_TransferConfig(hi2c,DevAddress, hi2c->XferSize, xfermode, xferrequest);
26912677

targets/TARGET_STM/TARGET_STM32L4/device/stm32l4xx_hal_i2c.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,7 +2571,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
25712571
/* Prepare transfer parameters */
25722572
hi2c->pBuffPtr = pData;
25732573
hi2c->XferCount = Size;
2574-
hi2c->XferOptions = XferOptions;
2574+
hi2c->XferOptions = (XferOptions & (~I2C_RELOAD_MODE));
25752575
hi2c->XferISR = I2C_Master_ISR_IT;
25762576

25772577
/* If size > MAX_NBYTE_SIZE, use reload mode */
@@ -2584,15 +2584,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
25842584
{
25852585
hi2c->XferSize = hi2c->XferCount;
25862586
xfermode = hi2c->XferOptions;
2587-
2588-
/* If transfer direction not change, do not generate Restart Condition */
2589-
/* Mean Previous state is same as current state */
2590-
if(hi2c->PreviousState == I2C_STATE_SLAVE_BUSY_TX)
2591-
{
2592-
xferrequest = I2C_NO_STARTSTOP;
2593-
}
25942587
}
2595-
25962588

25972589
/* Send Slave Address and set NBYTES to write */
25982590
I2C_TransferConfig(hi2c, DevAddress, hi2c->XferSize, xfermode, xferrequest);
@@ -2644,7 +2636,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c,
26442636
/* Prepare transfer parameters */
26452637
hi2c->pBuffPtr = pData;
26462638
hi2c->XferCount = Size;
2647-
hi2c->XferOptions = XferOptions;
2639+
hi2c->XferOptions = (XferOptions & (~I2C_RELOAD_MODE));
26482640
hi2c->XferISR = I2C_Master_ISR_IT;
26492641

26502642
/* If hi2c->XferCount > MAX_NBYTE_SIZE, use reload mode */
@@ -2657,13 +2649,6 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT(I2C_HandleTypeDef *hi2c,
26572649
{
26582650
hi2c->XferSize = hi2c->XferCount;
26592651
xfermode = hi2c->XferOptions;
2660-
2661-
/* If transfer direction not change, do not generate Restart Condition */
2662-
/* Mean Previous state is same as current state */
2663-
if(hi2c->PreviousState == I2C_STATE_MASTER_BUSY_RX)
2664-
{
2665-
xferrequest = I2C_NO_STARTSTOP;
2666-
}
26672652
}
26682653

26692654
/* Send Slave Address and set NBYTES to read */

0 commit comments

Comments
 (0)