fix: Pi 4 Bluetooth - hold RTS deasserted across BT_ON power-on, require Read Local Version to sync, mini UART no flow control first
This commit is contained in:
1 parent
93d8becce3
commit
3310b3d6de
11 files changed
+210
-38
No files matched your search
@@ -52,9 +52,16 @@ namespace Drivers::Serial::BtUart {
|
||||
static constexpr uint32_t MU_LSR_TX_IDLE = 1u << 6; // FIFO empty, shifter idle
|
||||
static constexpr uint32_t MU_CNTL_RXEN = 1u << 0;
|
||||
static constexpr uint32_t MU_CNTL_TXEN = 1u << 1;
|
||||
// Auto RTS at the default level (deassert with 3 FIFO spaces left) and
|
||||
// the default, active-low polarity (CNTL bit 6 would invert it).
|
||||
// Auto RTS at the default level (deassert with 3 FIFO spaces left).
|
||||
// Bit 6 picks the level auto RTS asserts: set = low, clear (the reset
|
||||
// value) = high. A UART's RTS is active low, so it must be set: left
|
||||
// clear, RTS reads "stop" to the controller the moment auto RTS is on.
|
||||
// Bits 3 and 7 are the same for CTS: on a Pi 400, with bit 7 clear the
|
||||
// transmitter held its bytes while the controller drove CTS low (ready).
|
||||
static constexpr uint32_t MU_CNTL_AUTORTS = 1u << 2;
|
||||
static constexpr uint32_t MU_CNTL_AUTOCTS = 1u << 3;
|
||||
static constexpr uint32_t MU_CNTL_RTS_LOW = 1u << 6;
|
||||
static constexpr uint32_t MU_CNTL_CTS_LOW = 1u << 7;
|
||||
|
||||
// PL011 (ARM PrimeCell UART TRM)
|
||||
static constexpr uint32_t PL_DR = 0x00;
|
||||
@@ -359,7 +366,9 @@ namespace Drivers::Serial::BtUart {
|
||||
if (!g_initialized) return;
|
||||
g_hwLock.Acquire();
|
||||
if (g_kind == Kind::MiniUart) {
|
||||
uint32_t cntl = MU_CNTL_RXEN | MU_CNTL_TXEN | (on ? MU_CNTL_AUTORTS : 0);
|
||||
uint32_t cntl = MU_CNTL_RXEN | MU_CNTL_TXEN
|
||||
| (on ? MU_CNTL_AUTORTS | MU_CNTL_RTS_LOW
|
||||
| MU_CNTL_AUTOCTS | MU_CNTL_CTS_LOW : 0);
|
||||
Write32(MU_CNTL, cntl);
|
||||
// With auto RTS off, hold RTS asserted by hand.
|
||||
Write32(MU_MCR, MU_MCR_RTS);
|
||||
@@ -372,6 +381,19 @@ namespace Drivers::Serial::BtUart {
|
||||
g_hwLock.Release();
|
||||
}
|
||||
|
||||
void DeassertRts() {
|
||||
if (!g_initialized) return;
|
||||
g_hwLock.Acquire();
|
||||
if (g_kind == Kind::MiniUart) {
|
||||
Write32(MU_CNTL, MU_CNTL_RXEN | MU_CNTL_TXEN);
|
||||
Write32(MU_MCR, 0);
|
||||
} else {
|
||||
Write32(PL_CR, Read32(PL_CR) & ~(PL_CR_RTSEN | PL_CR_CTSEN | PL_CR_RTS));
|
||||
}
|
||||
g_flowControl = false;
|
||||
g_hwLock.Release();
|
||||
}
|
||||
|
||||
int Read(uint8_t* buffer, int maxLength) {
|
||||
if (buffer == nullptr || maxLength <= 0) return 0;
|
||||
uint32_t tail = g_rxTail.load(std::memory_order_relaxed);
|
||||
|
||||
Reference in new issue
Block a user