Skip to content

Commit 9ca367c

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 9ca367c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/SPI.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ void SPI::_do_construct()
8181
if (!_peripheral) {
8282
_peripheral = SPI::_alloc();
8383
_peripheral->name = name;
84+
#if DEVICE_SPI_ASYNCH && TRANSACTION_QUEUE_SIZE_SPI
85+
// prime the SingletonPtr, so we don't have a problem trying to
86+
// construct the buffer if asynch operation initiated from IRQ
87+
_peripheral->transaction_buffer.get();
88+
#endif
8489
}
8590
core_util_critical_section_exit();
8691
// we don't need to _acquire at this stage.

0 commit comments

Comments
 (0)