@@ -300,7 +300,7 @@ static uint32_t i2c_getClkFreq(I2C_TypeDef *i2c)
300
300
Error_Handler ();
301
301
}
302
302
#else
303
- /* STM32 L0/G0 I2C2 has no independent clock */
303
+ /* STM32 L0/G0/U0 I2C2 has no independent clock */
304
304
clkSrcFreq = HAL_RCC_GetPCLK1Freq ();
305
305
#endif
306
306
}
@@ -406,7 +406,8 @@ static uint32_t i2c_getClkFreq(I2C_TypeDef *i2c)
406
406
Error_Handler ();
407
407
}
408
408
#else
409
- Error_Handler ();
409
+ /* STM32 U0 I2C4 has no independent clock */
410
+ clkSrcFreq = HAL_RCC_GetPCLK1Freq ();
410
411
#endif
411
412
}
412
413
}
@@ -675,9 +676,10 @@ void i2c_init(i2c_t *obj, uint32_t timing, uint32_t ownAddress)
675
676
__HAL_RCC_I2C1_RELEASE_RESET ();
676
677
677
678
obj -> irq = I2C1_EV_IRQn ;
678
- #if !defined(STM32C0xx ) && !defined(STM32F0xx ) && !defined(STM32G0xx ) && !defined(STM32L0xx )
679
+ #if !defined(STM32C0xx ) && !defined(STM32F0xx ) && !defined(STM32G0xx ) && \
680
+ !defined(STM32L0xx ) && !defined(STM32U0xx )
679
681
obj -> irqER = I2C1_ER_IRQn ;
680
- #endif /* !STM32C0xx && !STM32F0xx && !STM32G0xx && !STM32L0xx */
682
+ #endif /* !STM32C0xx && !STM32F0xx && !STM32G0xx && !STM32L0xx && !STM32U0xx */
681
683
i2c_handles [I2C1_INDEX ] = handle ;
682
684
}
683
685
#endif // I2C1_BASE
@@ -688,9 +690,10 @@ void i2c_init(i2c_t *obj, uint32_t timing, uint32_t ownAddress)
688
690
__HAL_RCC_I2C2_FORCE_RESET ();
689
691
__HAL_RCC_I2C2_RELEASE_RESET ();
690
692
obj -> irq = I2C2_EV_IRQn ;
691
- #if !defined(STM32F0xx ) && !defined(STM32G0xx ) && !defined(STM32L0xx )
693
+ #if !defined(STM32F0xx ) && !defined(STM32G0xx ) && !defined(STM32L0xx ) && \
694
+ !defined(STM32U0xx )
692
695
obj -> irqER = I2C2_ER_IRQn ;
693
- #endif /* !STM32F0xx && !STM32G0xx && !STM32L0xx */
696
+ #endif /* !STM32F0xx && !STM32G0xx && !STM32L0xx && !STM32U0xx */
694
697
i2c_handles [I2C2_INDEX ] = handle ;
695
698
}
696
699
#endif // I2C2_BASE
@@ -701,9 +704,9 @@ void i2c_init(i2c_t *obj, uint32_t timing, uint32_t ownAddress)
701
704
__HAL_RCC_I2C3_FORCE_RESET ();
702
705
__HAL_RCC_I2C3_RELEASE_RESET ();
703
706
obj -> irq = I2C3_EV_IRQn ;
704
- #if !defined(STM32G0xx ) && !defined(STM32L0xx )
707
+ #if !defined(STM32G0xx ) && !defined(STM32L0xx ) && !defined( STM32U0xx )
705
708
obj -> irqER = I2C3_ER_IRQn ;
706
- #endif /* !STM32G0xx && !STM32L0xx */
709
+ #endif /* !STM32G0xx && !STM32L0xx && !STM32U0xx */
707
710
i2c_handles [I2C3_INDEX ] = handle ;
708
711
}
709
712
#endif // I2C3_BASE
@@ -714,7 +717,9 @@ void i2c_init(i2c_t *obj, uint32_t timing, uint32_t ownAddress)
714
717
__HAL_RCC_I2C4_FORCE_RESET ();
715
718
__HAL_RCC_I2C4_RELEASE_RESET ();
716
719
obj -> irq = I2C4_EV_IRQn ;
720
+ #if !defined(STM32U0xx )
717
721
obj -> irqER = I2C4_ER_IRQn ;
722
+ #endif /* !STM32U0xx */
718
723
i2c_handles [I2C4_INDEX ] = handle ;
719
724
}
720
725
#endif // I2C4_BASE
@@ -769,10 +774,11 @@ void i2c_init(i2c_t *obj, uint32_t timing, uint32_t ownAddress)
769
774
770
775
HAL_NVIC_SetPriority (obj -> irq , I2C_IRQ_PRIO , I2C_IRQ_SUBPRIO );
771
776
HAL_NVIC_EnableIRQ (obj -> irq );
772
- #if !defined(STM32C0xx ) && !defined(STM32F0xx ) && !defined(STM32G0xx ) && !defined(STM32L0xx )
777
+ #if !defined(STM32C0xx ) && !defined(STM32F0xx ) && !defined(STM32G0xx ) && \
778
+ !defined(STM32L0xx ) && !defined(STM32U0xx )
773
779
HAL_NVIC_SetPriority (obj -> irqER , I2C_IRQ_PRIO , I2C_IRQ_SUBPRIO );
774
780
HAL_NVIC_EnableIRQ (obj -> irqER );
775
- #endif /* !STM32C0xx && !STM32F0xx && !STM32G0xx && !STM32L0xx */
781
+ #endif /* !STM32C0xx && !STM32F0xx && !STM32G0xx && !STM32L0xx && !STM32U0xx */
776
782
777
783
/* Init the I2C */
778
784
if (HAL_I2C_Init (handle ) != HAL_OK ) {
@@ -796,9 +802,10 @@ void i2c_init(i2c_t *obj, uint32_t timing, uint32_t ownAddress)
796
802
void i2c_deinit (i2c_t * obj )
797
803
{
798
804
HAL_NVIC_DisableIRQ (obj -> irq );
799
- #if !defined(STM32C0xx ) && !defined(STM32F0xx ) && !defined(STM32G0xx ) && !defined(STM32L0xx )
805
+ #if !defined(STM32C0xx ) && !defined(STM32F0xx ) && !defined(STM32G0xx ) && \
806
+ !defined(STM32L0xx ) && !defined(STM32U0xx )
800
807
HAL_NVIC_DisableIRQ (obj -> irqER );
801
- #endif /* !STM32C0xx && !STM32F0xx && !STM32G0xx && !STM32L0xx */
808
+ #endif /* !STM32C0xx && !STM32F0xx && !STM32G0xx && !STM32L0xx && !STM32U0xx */
802
809
HAL_I2C_DeInit (& (obj -> handle ));
803
810
/* Reset I2C GPIO pins as INPUT_ANALOG */
804
811
pin_function (obj -> scl , STM_PIN_DATA (STM_MODE_ANALOG , GPIO_NOPULL , 0 ));
@@ -1221,12 +1228,14 @@ void I2C1_EV_IRQHandler(void)
1221
1228
{
1222
1229
I2C_HandleTypeDef * handle = i2c_handles [I2C1_INDEX ];
1223
1230
HAL_I2C_EV_IRQHandler (handle );
1224
- #if defined(STM32C0xx ) || defined(STM32F0xx ) || defined(STM32G0xx ) || defined(STM32L0xx )
1231
+ #if defined(STM32C0xx ) || defined(STM32F0xx ) || defined(STM32G0xx ) || \
1232
+ defined(STM32L0xx ) || defined(STM32U0xx )
1225
1233
HAL_I2C_ER_IRQHandler (handle );
1226
- #endif /* STM32C0xx || STM32F0xx || STM32G0xx || STM32L0xx */
1234
+ #endif /* STM32C0xx || STM32F0xx || STM32G0xx || STM32L0xx || STM32U0xx */
1227
1235
}
1228
1236
1229
- #if !defined(STM32C0xx ) && !defined(STM32F0xx ) && !defined(STM32G0xx ) && !defined(STM32L0xx )
1237
+ #if !defined(STM32C0xx ) && !defined(STM32F0xx ) && !defined(STM32G0xx ) && \
1238
+ !defined(STM32L0xx ) && !defined(STM32U0xx )
1230
1239
/**
1231
1240
* @brief This function handles I2C1 interrupt.
1232
1241
* @param None
@@ -1237,7 +1246,7 @@ void I2C1_ER_IRQHandler(void)
1237
1246
I2C_HandleTypeDef * handle = i2c_handles [I2C1_INDEX ];
1238
1247
HAL_I2C_ER_IRQHandler (handle );
1239
1248
}
1240
- #endif /* !STM32C0xx && !STM32F0xx && !STM32G0xx && !STM32L0xx */
1249
+ #endif /* !STM32C0xx && !STM32F0xx && !STM32G0xx && !STM32L0xx && !STM32U0xx */
1241
1250
#endif // I2C1_BASE
1242
1251
1243
1252
#if defined(I2C2_BASE )
@@ -1248,7 +1257,7 @@ void I2C1_ER_IRQHandler(void)
1248
1257
*/
1249
1258
void I2C2_EV_IRQHandler (void )
1250
1259
{
1251
- #if defined(I2C3_BASE ) && defined(STM32G0xx )
1260
+ #if defined(I2C3_BASE ) && ( defined(STM32G0xx ) || defined( STM32U0xx ) )
1252
1261
/* I2C2_3_IRQHandler */
1253
1262
I2C_HandleTypeDef * handle2 = i2c_handles [I2C2_INDEX ];
1254
1263
I2C_HandleTypeDef * handle3 = i2c_handles [I2C3_INDEX ];
@@ -1260,16 +1269,26 @@ void I2C2_EV_IRQHandler(void)
1260
1269
HAL_I2C_EV_IRQHandler (handle3 );
1261
1270
HAL_I2C_ER_IRQHandler (handle3 );
1262
1271
}
1272
+ #if defined(I2C4_BASE )
1273
+ /* I2C2_3_4_IRQHandler */
1274
+ I2C_HandleTypeDef * handle4 = i2c_handles [I2C4_INDEX ];
1275
+ if (handle4 ) {
1276
+ HAL_I2C_EV_IRQHandler (handle4 );
1277
+ HAL_I2C_ER_IRQHandler (handle4 );
1278
+ }
1279
+ #endif /* I2C4_BASE */
1263
1280
#else
1264
1281
I2C_HandleTypeDef * handle = i2c_handles [I2C2_INDEX ];
1265
1282
HAL_I2C_EV_IRQHandler (handle );
1266
- #if defined(STM32F0xx ) || defined(STM32G0xx ) || defined(STM32L0xx )
1283
+ #if defined(STM32F0xx ) || defined(STM32G0xx ) || defined(STM32L0xx ) || \
1284
+ defined(STM32U0xx )
1267
1285
HAL_I2C_ER_IRQHandler (handle );
1268
- #endif /* STM32F0xx || STM32G0xx || STM32L0xx */
1286
+ #endif /* STM32F0xx || STM32G0xx || STM32L0xx || STM32U0xx */
1269
1287
#endif
1270
1288
}
1271
1289
1272
- #if !defined(STM32F0xx ) && !defined(STM32G0xx ) && !defined(STM32L0xx )
1290
+ #if !defined(STM32F0xx ) && !defined(STM32G0xx ) && !defined(STM32L0xx ) && \
1291
+ !defined(STM32U0xx )
1273
1292
/**
1274
1293
* @brief This function handles I2C2 interrupt.
1275
1294
* @param None
@@ -1280,10 +1299,10 @@ void I2C2_ER_IRQHandler(void)
1280
1299
I2C_HandleTypeDef * handle = i2c_handles [I2C2_INDEX ];
1281
1300
HAL_I2C_ER_IRQHandler (handle );
1282
1301
}
1283
- #endif /* !STM32F0xx && !STM32G0xx && !STM32L0xx */
1302
+ #endif /* !STM32F0xx && !STM32G0xx && !STM32L0xx && !STM32U0xx */
1284
1303
#endif // I2C2_BASE
1285
1304
1286
- #if defined(I2C3_BASE ) && !defined(STM32G0xx )
1305
+ #if defined(I2C3_BASE ) && !defined(STM32G0xx ) && !defined( STM32U0xx )
1287
1306
/**
1288
1307
* @brief This function handles I2C3 interrupt.
1289
1308
* @param None
@@ -1310,9 +1329,9 @@ void I2C3_ER_IRQHandler(void)
1310
1329
HAL_I2C_ER_IRQHandler (handle );
1311
1330
}
1312
1331
#endif /* !STM32L0xx */
1313
- #endif /* I2C3_BASE && ! STM32G0xx */
1332
+ #endif /* I2C3_BASE && ! STM32G0xx && !STM32U0xx */
1314
1333
1315
- #if defined(I2C4_BASE )
1334
+ #if defined(I2C4_BASE ) && !defined( STM32U0xx )
1316
1335
/**
1317
1336
* @brief This function handles I2C4 interrupt.
1318
1337
* @param None
@@ -1335,7 +1354,7 @@ void I2C4_ER_IRQHandler(void)
1335
1354
I2C_HandleTypeDef * handle = i2c_handles [I2C4_INDEX ];
1336
1355
HAL_I2C_ER_IRQHandler (handle );
1337
1356
}
1338
- #endif // I2C4_BASE
1357
+ #endif // I2C4_BASE && !STM32U0xx
1339
1358
1340
1359
#if defined(I2C5_BASE )
1341
1360
/**
0 commit comments