Skip to content

Commit cc9c716

Browse files
facchinmpenna
authored and
penna
committed
STM32H7: I2C: allow overriding APB1CLK multiplier
Conflicts: targets/targets.json -> merged
1 parent 18444ea commit cc9c716

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

targets/TARGET_STM/TARGET_STM32H7/i2c_device.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ extern "C" {
4848
#define I2CAPI_I2C3_CLKSRC RCC_I2C3CLKSOURCE_D2PCLK1
4949
#define I2CAPI_I2C4_CLKSRC RCC_I2C4CLKSOURCE_D3PCLK1
5050

51+
#if (APB1CLK)
52+
#define APB1CLK_MULTIPLIER (APB1CLK / 54000000)
53+
#else
54+
#define APB1CLK_MULTIPLIER (1)
55+
#endif
56+
5157
/* Provide the suitable timing depending on requested frequencie */
5258
static inline uint32_t get_i2c_timing(int hz)
5359
{
@@ -64,13 +70,13 @@ static inline uint32_t get_i2c_timing(int hz)
6470
*/
6571
switch (hz) {
6672
case 100000:
67-
tim = 0x10916998; // Standard mode with Rise time = 120ns, Fall time = 120ns
73+
tim = 0x10916998 * APB1CLK_MULTIPLIER; // Standard mode with Rise time = 120ns, Fall time = 120ns
6874
break;
6975
case 400000:
70-
tim = 0x00B11B54; // Fast Mode with Rise time = 120ns, Fall time = 120ns
76+
tim = 0x00B11B54 * APB1CLK_MULTIPLIER; // Fast Mode with Rise time = 120ns, Fall time = 120ns
7177
break;
7278
case 1000000:
73-
tim = 0x0090091B; // Fast Mode Plus with Rise time = 120ns, Fall time = 10ns
79+
tim = 0x0090091B * APB1CLK_MULTIPLIER; // Fast Mode Plus with Rise time = 120ns, Fall time = 10ns
7480
break;
7581
default:
7682
break;

targets/targets.json

+5
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,11 @@
24392439
"value": "USE_PLL_HSE_EXTC",
24402440
"macro_name": "CLOCK_SOURCE"
24412441
},
2442+
"abp1_clock": {
2443+
"help": "ABP1 clock to fix I2C speed calculation",
2444+
"value": "112500000",
2445+
"macro_name": "APB1CLK"
2446+
},
24422447
"lpticker_lptim": {
24432448
"help": "This target supports LPTIM. Set value 1 to use LPTIM for LPTICKER, or 0 to use RTC wakeup timer",
24442449
"value": 1

0 commit comments

Comments
 (0)