This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch releases/13.0
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/releases/13.0 by this push:
new b7c3b392a99 drivers/spi/ice40: fix operator precedence in final clock
cycle count
b7c3b392a99 is described below
commit b7c3b392a99e404560fbc7fa37286364abd44227
Author: yi chen <[email protected]>
AuthorDate: Sun Jul 12 22:04:22 2026 +0800
drivers/spi/ice40: fix operator precedence in final clock cycle count
ice40_endwrite() computes how many dummy SPI bytes to clock out after
the bitstream to finish FPGA configuration with:
for (size_t i = 0; i < ICE40_SPI_FINAL_CLK_CYCLES + 7 / 8; i++)
`/` binds tighter than `+` in C, so this parses as
ICE40_SPI_FINAL_CLK_CYCLES + (7 / 8) = 160 + 0 = 160, i.e. the "+ 7 / 8"
is a silent no-op. The macro name and the classic `(n + 7) / 8`
ceiling-division idiom (used elsewhere in embedded code to convert a
bit/cycle count into a byte count) make clear the intent was to send
ceil(ICE40_SPI_FINAL_CLK_CYCLES / 8) = 20 bytes (160 SPI clock cycles,
matching the macro name). Instead the unmodified code sends 160 bytes,
i.e. 1280 clock cycles - 8x more than intended.
Fix by parenthesizing the ceiling-division: (ICE40_SPI_FINAL_CLK_CYCLES
+ 7) / 8, which evaluates to 20, restoring the intended 160-clock-cycle
finalization sequence.
Fixes #19367
Assisted-by: Claude Code:claude-sonnet-5
Signed-off-by: yi chen <[email protected]>
---
drivers/spi/ice40.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/ice40.c b/drivers/spi/ice40.c
index 3c69d03e546..bb216e30d4d 100644
--- a/drivers/spi/ice40.c
+++ b/drivers/spi/ice40.c
@@ -269,7 +269,7 @@ ice40_endwrite(FAR struct ice40_dev_s *dev)
dev->ops->select(dev, false);
- for (size_t i = 0; i < ICE40_SPI_FINAL_CLK_CYCLES + 7 / 8; i++)
+ for (size_t i = 0; i < (ICE40_SPI_FINAL_CLK_CYCLES + 7) / 8; i++)
{
SPI_SEND(dev->spi, 0xff);
}