Skip to content

Commit 860f9c8

Browse files
Finomnisfabiobaltieri
authored andcommitted
spi_nxp_lpspi: Fix underflow in lpspi sck calculation
If `desired_delay_ns` is `0`, it is much saner to set the delay to `0x00` than to underflow and set it to `0xff`, which is the current behavior. Signed-off-by: Martin Stumpf <[email protected]>
1 parent be38568 commit 860f9c8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi_common.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ static uint8_t lpspi_calc_delay_scaler(uint32_t desired_delay_ns,
132132
delay_cycles = (uint64_t)prescaled_clock * desired_delay_ns;
133133
delay_cycles = DIV_ROUND_UP(delay_cycles, NSEC_PER_SEC);
134134

135-
/* what the min_cycles parameter is about is that
135+
/* clamp to minimally possible cycles to avoid underflow */
136+
delay_cycles = MAX(delay_cycles, min_cycles);
137+
138+
/* what the min_cycles parameter is about is that
136139
* PCSSCK and SCKPSC are +1 cycles of the programmed value,
137140
* while DBT is +2 cycles of the programmed value.
138141
* So this calculates the value to program to the register.

0 commit comments

Comments
 (0)