[timeout, stm32wb, pic32cz] Implement an optional timeout and add it to current drivers#16
Open
AlexLanzano wants to merge 1 commit intowolfSSL:mainfrom
Open
[timeout, stm32wb, pic32cz] Implement an optional timeout and add it to current drivers#16AlexLanzano wants to merge 1 commit intowolfSSL:mainfrom
AlexLanzano wants to merge 1 commit intowolfSSL:mainfrom
Conversation
…to current drivers
There was a problem hiding this comment.
Pull request overview
This PR introduces a lightweight timeout abstraction to bound polling loops, integrates it into several STM32WB and PIC32CZ drivers, and wires it into the STM32WB Nucleo board plus core tests.
Changes:
- Add
whal_Timeout+WHAL_TIMEOUT_*macros (with optional compile-out) and a newWHAL_ETIMEOUTerror code. - Extend multiple driver config structs to accept an optional timeout pointer and apply timeouts to busy-wait/polling loops.
- Add core unit tests for timeout behavior and configure an example tick source + timeout instance on the STM32WB55 Nucleo board.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| wolfHAL/wolfHAL.h | Exposes the new timeout API from the umbrella header. |
| wolfHAL/uart/stm32wb_uart.h | Adds optional timeout pointer to STM32WB UART config. |
| wolfHAL/uart/pic32cz_uart.h | Adds optional timeout pointer to PIC32CZ UART config. |
| wolfHAL/timeout.h | Introduces the timeout abstraction and macros. |
| wolfHAL/spi/stm32wb_spi.h | Adds optional timeout pointer to STM32WB SPI config. |
| wolfHAL/rng/stm32wb_rng.h | Adds optional timeout pointer to STM32WB RNG config. |
| wolfHAL/flash/stm32wb_flash.h | Adds optional timeout pointer to STM32WB Flash config. |
| wolfHAL/flash/pic32cz_flash.h | Adds optional timeout pointer to PIC32CZ Flash config. |
| wolfHAL/error.h | Adds WHAL_ETIMEOUT error code. |
| wolfHAL/crypto/stm32wb_aes.h | Adds optional timeout pointer to STM32WB AES config. |
| tests/core/test_timeout.c | Adds unit tests for timeout start/stop/expired and wrap behavior. |
| tests/core/main.c | Registers/runs the new timeout test suite. |
| tests/core/Makefile | Includes test_timeout.c in the core test build. |
| src/uart/stm32wb_uart.c | Applies timeout guards to STM32WB UART send/recv polling. |
| src/uart/pic32cz_uart.c | Adds timeout-bounded sync waits and TX/RX polling with timeout errors. |
| src/spi/stm32wb_spi.c | Adds timeout-bounded polling for TXE/RXNE/BSY in SPI transfers. |
| src/rng/stm32wb_rng.c | Adds timeout-bounded wait for RNG data-ready. |
| src/flash/stm32wb_flash.c | Adds timeout-bounded waits for flash CFGBSY during program/erase. |
| src/flash/pic32cz_flash.c | Adds timeout-bounded mutex/busy waits and propagates timeout errors. |
| src/crypto/stm32wb_aes.c | Adds timeout-bounded polling for AES completion across modes. |
| boards/stm32wb55xx_nucleo/board.h | Updates tick type to uint64_t for the new timeout tick source. |
| boards/stm32wb55xx_nucleo/board.c | Implements Board_GetTick(), defines a default timeout instance, and injects it into device configs. |
Comments suppressed due to low confidence (4)
src/flash/pic32cz_flash.c:363
cfgis read fromflashDevbefore checkingflashDevfor NULL, which can dereference a NULL pointer. Move thecfgassignment after theif (!flashDev)validation (and consider also validatingflashDev->cfg).
whal_Error whal_Pic32czFlash_Erase(whal_Flash *flashDev, size_t addr, size_t dataSz)
{
const whal_Regmap *reg;
whal_Pic32czFlash_Cfg *cfg = flashDev->cfg;
whal_Error err;
size_t pageAddr;
size_t endAddr;
if (!flashDev) {
return WHAL_EINVAL;
}
src/flash/pic32cz_flash.c:256
cfgis read fromflashDevbefore validatingflashDevis non-NULL, which can dereference a NULL pointer when callers passflashDev == NULL. Movewhal_Pic32czFlash_Cfg *cfg = flashDev->cfg;to after theif (!flashDev || !data)check (and similarly in the other APIs in this file).
const whal_Regmap *reg;
whal_Pic32czFlash_Cfg *cfg = flashDev->cfg;
uint8_t *flashAddr = (uint8_t *)addr;
whal_Error err;
size_t i;
if (!flashDev || !data) {
return WHAL_EINVAL;
}
src/flash/pic32cz_flash.c:287
cfgis read fromflashDevbefore theif (!flashDev || !data)guard, which can dereference NULL whenflashDevis NULL. Assigncfgonly after validatingflashDev(andflashDev->cfgif required).
size_t dataSz)
{
const whal_Regmap *reg;
whal_Pic32czFlash_Cfg *cfg = flashDev->cfg;
const uint32_t *src;
whal_Error err;
size_t offset = 0;
if (!flashDev || !data) {
return WHAL_EINVAL;
}
boards/stm32wb55xx_nucleo/board.c:188
Board_WaitMs()still usessize_tlocals (startCount,currentCount) even thoughg_tickis nowuint64_t. This truncates the tick value on 32-bit builds and makes the wrap/overflow handling (g_tickOverflow,SIZE_MAX) inconsistent with the actual counter type. Update the delay logic to useuint64_tconsistently (and drop the overflow flag if 64-bit wrap is no longer a practical concern).
void Board_WaitMs(size_t ms)
{
size_t startCount = g_tick;
g_waiting = 1;
while (1) {
size_t currentCount = g_tick;
if (g_tickOverflow) {
if ((SIZE_MAX - startCount) + currentCount > ms) {
break;
}
} else if (currentCount - startCount > ms) {
break;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+241
to
+245
| WHAL_TIMEOUT_START(cfg->timeout); | ||
| while (!(whal_Reg_Read(base, AES_SR_REG) & AES_SR_CCF_Msk)) { | ||
| if (WHAL_TIMEOUT_EXPIRED(cfg->timeout)) | ||
| return WHAL_ETIMEOUT; | ||
| } |
Comment on lines
+868
to
+872
| WHAL_TIMEOUT_START(cfg->timeout); | ||
| while (!(whal_Reg_Read(base, AES_SR_REG) & AES_SR_CCF_Msk)) { | ||
| if (WHAL_TIMEOUT_EXPIRED(cfg->timeout)) | ||
| return WHAL_ETIMEOUT; | ||
| } |
Comment on lines
84
to
+91
| if (!rngDev || !rngData) { | ||
| return WHAL_EINVAL; | ||
| } | ||
|
|
||
| whal_Error err = WHAL_SUCCESS; | ||
| whal_Stm32wbRng_Cfg *cfg = (whal_Stm32wbRng_Cfg *)rngDev->cfg; | ||
| const whal_Regmap *reg = &rngDev->regmap; | ||
| size_t status; | ||
| size_t sr; |
Comment on lines
205
to
209
| if (args->sz == 0 || (args->sz & 0xF) != 0) | ||
| return WHAL_EINVAL; | ||
|
|
||
| cfg = (const whal_Stm32wbAes_Cfg *)cryptoDev->cfg; | ||
| base = cryptoDev->regmap.base; |
Comment on lines
427
to
431
| if (args->tagSz == 0 || args->tagSz > 16) | ||
| return WHAL_EINVAL; | ||
|
|
||
| cfg = (const whal_Stm32wbAes_Cfg *)cryptoDev->cfg; | ||
| base = cryptoDev->regmap.base; |
Comment on lines
347
to
351
| if (args->sz == 0 || (args->sz & 0xF) != 0) | ||
| return WHAL_EINVAL; | ||
|
|
||
| cfg = (const whal_Stm32wbAes_Cfg *)cryptoDev->cfg; | ||
| base = cryptoDev->regmap.base; |
Comment on lines
+382
to
+386
| WHAL_TIMEOUT_START(cfg->timeout); | ||
| while (!(whal_Reg_Read(base, AES_SR_REG) & AES_SR_CCF_Msk)) { | ||
| if (WHAL_TIMEOUT_EXPIRED(cfg->timeout)) | ||
| return WHAL_ETIMEOUT; | ||
| } |
Comment on lines
+654
to
+658
| WHAL_TIMEOUT_START(cfg->timeout); | ||
| while (!(whal_Reg_Read(base, AES_SR_REG) & AES_SR_CCF_Msk)) { | ||
| if (WHAL_TIMEOUT_EXPIRED(cfg->timeout)) | ||
| return WHAL_ETIMEOUT; | ||
| } |
|
|
||
| uint64_t Board_GetTick() | ||
| { | ||
| return g_tick; |
Comment on lines
220
to
+224
| /* Wait for CTRLB sync */ | ||
| whal_Pic32czUart_WaitSync(reg, USART_SYNCBUSY_CTRLB_Msk, USART_SYNCBUSY_CTRLB_Pos); | ||
| err = whal_Pic32czUart_WaitSync(reg, USART_SYNCBUSY_CTRLB_Msk, | ||
| USART_SYNCBUSY_CTRLB_Pos, cfg->timeout); | ||
| if (err != WHAL_SUCCESS) | ||
| return err; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.