nuttx/drivers/spi
yi chen 864c97f1d9 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 <94xhn1@gmail.com>
2026-07-20 17:05:01 +08:00
..
CMakeLists.txt drivers/spi/CMakeLists.txt: Aligned Cmake with Make 2025-08-22 08:18:50 -03:00
ice40.c drivers/spi/ice40: fix operator precedence in final clock cycle count 2026-07-20 17:05:01 +08:00
Kconfig drivers/spi: Add support for FPGA iCE40 bitstream loading. 2024-04-12 10:19:58 -03:00
Make.defs drivers: migrate to SPDX identifier 2024-11-06 18:02:25 +08:00
qspi_flash.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
spi_bitbang.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
spi_driver.c drivers/: Multiple Drivers Are Registered With World Writable - Part 2 2026-07-15 15:27:28 +08:00
spi_flash.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
spi_slave_driver.c drivers/: Multiple Drivers Are Registered With World Writable - Part 2 2026-07-15 15:27:28 +08:00
spi_transfer.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00