Skip to content

Commit 3be7100

Browse files
oflebbeaykevl
authored andcommitted
fix(rp2): possible integer overflow while computing factors for SPI baudrate
Incorrect factors are calculated for baudrates which are a bit larger than integer multiples of 4194304. For example for baudrates of 8_400_000 or 58_800_000. Fixed the same way in newer versions of the RPI SDK.
1 parent aedaf7d commit 3be7100

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/machine/machine_rp2_spi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (spi *SPI) SetBaudRate(br uint32) error {
108108
var prescale, postdiv uint32
109109
freq := CPUFrequency()
110110
for prescale = 2; prescale < 255; prescale += 2 {
111-
if freq < (prescale+2)*256*br {
111+
if uint64(freq) < uint64((prescale+2)*256)*uint64(br) {
112112
break
113113
}
114114
}

0 commit comments

Comments
 (0)