Skip to content

Commit

Permalink
SPI: Prime asynch transaction buffer on construction
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
kjbracey committed Apr 25, 2019
1 parent beed42e commit 3fbad10
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ void SPI::_do_construct()
_peripheral->name = name;
}
core_util_critical_section_exit();

#if DEVICE_SPI_ASYNCH && TRANSACTION_QUEUE_SIZE_SPI
// prime the SingletonPtr, so we don't have a problem trying to
// construct the buffer if asynch operation initiated from IRQ
_peripheral->transaction_buffer.get();
#endif
// we don't need to _acquire at this stage.
// this will be done anyway before any operation.
}
Expand Down

0 comments on commit 3fbad10

Please sign in to comment.