Skip to content

Commit 3fbad10

Browse files
committed
SPI: Prime asynch transaction buffer on construction
SPI peripherals' asynch transaction buffers are now wrapped by SingletonPtr, which needs to take the singleton_lock Mutex when first accessed. If it was first accessed by an asynch transaction started from IRQ, that would not be possible. Add a SingletonPtr::get() call to the SPI construction process so that the peripheral's buffer is fully constructed before any SPI methods can be called, meaning asynch methods won't fail from IRQ. (Other pre-existing synchronisation issues with async remain, but this avoids a new trap in Mbed OS 5.12).
1 parent beed42e commit 3fbad10

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/SPI.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ void SPI::_do_construct()
8383
_peripheral->name = name;
8484
}
8585
core_util_critical_section_exit();
86+
87+
#if DEVICE_SPI_ASYNCH && TRANSACTION_QUEUE_SIZE_SPI
88+
// prime the SingletonPtr, so we don't have a problem trying to
89+
// construct the buffer if asynch operation initiated from IRQ
90+
_peripheral->transaction_buffer.get();
91+
#endif
8692
// we don't need to _acquire at this stage.
8793
// this will be done anyway before any operation.
8894
}

0 commit comments

Comments
 (0)