Skip to content

Arithmetic underflow in SPI read routines #337

@michaelstoops

Description

@michaelstoops

I've identified an arithmetic underflow in the SPI read routines which seems to lead a deadlock, at least in my application.

The repeatability code is raspberrypi/pico-examples#101, in the case that the SPI slave starts while the SPI master is in the middle of a transmission. The slave correctly transmits 8 bytes and then deadlocks.

The flaw is in

if (tx_remaining && spi_is_writable(spi) && rx_remaining - tx_remaining < fifo_depth) {
and similar lines below. In the error condition, tx_remaining is 248 while rx_remaining is 247. The operation underflows and gives a result of 0xFF FF FF FF FF FF FF FF.

I'm not 100% clear on what happens next, and it probably depends on the timing of signals coming in anyway. Either way, I think the arithmetic underflow is not intended.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions