|
9 | 9 |
|
10 | 10 | /* SysTick timing */ |
11 | 11 | volatile uint32_t g_tick = 0; |
12 | | -volatile uint8_t g_waiting = 0; |
13 | | -volatile uint8_t g_tickOverflow = 0; |
14 | 12 |
|
15 | | -void SysTick_Handler() |
| 13 | +void SysTick_Handler(void) |
16 | 14 | { |
17 | | - uint32_t tickBefore = g_tick++; |
18 | | - if (g_waiting) { |
19 | | - if (tickBefore > g_tick) |
20 | | - g_tickOverflow = 1; |
21 | | - } |
| 15 | + g_tick++; |
22 | 16 | } |
23 | 17 |
|
24 | 18 | uint32_t Board_GetTick(void) |
@@ -64,6 +58,7 @@ static const whal_Stm32wbRcc_Clk g_clocks[] = { |
64 | 58 | {WHAL_STM32WB55_SPI1_CLOCK}, |
65 | 59 | {WHAL_STM32WB55_RNG_CLOCK}, |
66 | 60 | {WHAL_STM32WB55_AES1_CLOCK}, |
| 61 | + {WHAL_STM32WB55_I2C1_CLOCK}, |
67 | 62 | }; |
68 | 63 | #define CLOCK_COUNT (sizeof(g_clocks) / sizeof(g_clocks[0])) |
69 | 64 |
|
@@ -135,11 +130,39 @@ whal_Gpio g_whalGpio = { |
135 | 130 | .speed = WHAL_STM32WB_GPIO_SPEED_FAST, |
136 | 131 | .pull = WHAL_STM32WB_GPIO_PULL_UP, |
137 | 132 | }, |
| 133 | + [I2C_SCL_PIN] = { /* I2C1 SCL */ |
| 134 | + .port = WHAL_STM32WB_GPIO_PORT_B, |
| 135 | + .pin = 8, |
| 136 | + .mode = WHAL_STM32WB_GPIO_MODE_ALTFN, |
| 137 | + .outType = WHAL_STM32WB_GPIO_OUTTYPE_OPENDRAIN, |
| 138 | + .speed = WHAL_STM32WB_GPIO_SPEED_FAST, |
| 139 | + .pull = WHAL_STM32WB_GPIO_PULL_UP, |
| 140 | + .altFn = 4, |
| 141 | + }, |
| 142 | + [I2C_SDA_PIN] = { /* I2C1 SDA */ |
| 143 | + .port = WHAL_STM32WB_GPIO_PORT_B, |
| 144 | + .pin = 9, |
| 145 | + .mode = WHAL_STM32WB_GPIO_MODE_ALTFN, |
| 146 | + .outType = WHAL_STM32WB_GPIO_OUTTYPE_OPENDRAIN, |
| 147 | + .speed = WHAL_STM32WB_GPIO_SPEED_FAST, |
| 148 | + .pull = WHAL_STM32WB_GPIO_PULL_UP, |
| 149 | + .altFn = 4, |
| 150 | + }, |
138 | 151 | }, |
139 | 152 | .pinCount = PIN_COUNT, |
140 | 153 | }, |
141 | 154 | }; |
142 | 155 |
|
| 156 | +/* I2C */ |
| 157 | +whal_I2c g_whalI2c = { |
| 158 | + WHAL_STM32WB55_I2C1_DEVICE, |
| 159 | + |
| 160 | + .cfg = &(whal_Stm32wbI2c_Cfg) { |
| 161 | + .pclk = 64000000, |
| 162 | + .timeout = &g_whalTimeout, |
| 163 | + }, |
| 164 | +}; |
| 165 | + |
143 | 166 | /* SPI */ |
144 | 167 | whal_Spi g_whalSpi = { |
145 | 168 | WHAL_STM32WB55_SPI1_DEVICE, |
@@ -259,20 +282,7 @@ whal_Crypto g_whalCrypto = { |
259 | 282 | void Board_WaitMs(size_t ms) |
260 | 283 | { |
261 | 284 | uint32_t startCount = g_tick; |
262 | | - g_waiting = 1; |
263 | | - while (1) { |
264 | | - uint32_t currentCount = g_tick; |
265 | | - if (g_tickOverflow) { |
266 | | - if ((UINT32_MAX - startCount) + currentCount > ms) { |
267 | | - break; |
268 | | - } |
269 | | - } else if (currentCount - startCount > ms) { |
270 | | - break; |
271 | | - } |
272 | | - } |
273 | | - |
274 | | - g_waiting = 0; |
275 | | - g_tickOverflow = 0; |
| 285 | + while (g_tick - startCount < ms); |
276 | 286 | } |
277 | 287 |
|
278 | 288 | whal_Error Board_Init(void) |
@@ -347,6 +357,11 @@ whal_Error Board_Init(void) |
347 | 357 | return err; |
348 | 358 | } |
349 | 359 |
|
| 360 | + err = whal_I2c_Init(&g_whalI2c); |
| 361 | + if (err) { |
| 362 | + return err; |
| 363 | + } |
| 364 | + |
350 | 365 | err = whal_Flash_Init(&g_whalFlash); |
351 | 366 | if (err) { |
352 | 367 | return err; |
@@ -414,6 +429,11 @@ whal_Error Board_Deinit(void) |
414 | 429 | return err; |
415 | 430 | } |
416 | 431 |
|
| 432 | + err = whal_I2c_Deinit(&g_whalI2c); |
| 433 | + if (err) { |
| 434 | + return err; |
| 435 | + } |
| 436 | + |
417 | 437 | err = whal_Spi_Deinit(&g_whalSpi); |
418 | 438 | if (err) { |
419 | 439 | return err; |
|
0 commit comments