Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/Emulator/Peripherals/Peripherals/SPI/STM32SPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public STM32SPI(IMachine machine, int bufferCapacity = DefaultBufferCapacity) :
{
receiveBuffer = new CircularBuffer<byte>(bufferCapacity);
IRQ = new GPIO();
DMARecieve = new GPIO();
DMAReceive = new GPIO();
registers = new DoubleWordRegisterCollection(this);
SetupRegisters();
Reset();
Expand Down Expand Up @@ -75,7 +75,7 @@ public void WriteDoubleWord(long offset, uint value)
public override void Reset()
{
IRQ.Unset();
DMARecieve.Unset();
DMAReceive.Unset();
lock(receiveBuffer)
{
receiveBuffer.Clear();
Expand All @@ -93,7 +93,7 @@ public long Size

public GPIO IRQ { get; }

public GPIO DMARecieve { get; }
public GPIO DMAReceive { get; }

private uint HandleDataRead()
{
Expand Down Expand Up @@ -124,14 +124,19 @@ private void HandleDataWrite(uint value)
receiveBuffer.Enqueue(0x0);
return;
}
var response = peripheral.Transmit((byte)value); // currently byte mode is the only one we support
if (data16Bit.Value)
{
var responseHigh = peripheral.Transmit((byte)(value >> 8));
receiveBuffer.Enqueue(responseHigh);
}
var response = peripheral.Transmit((byte)value);
receiveBuffer.Enqueue(response);
if(rxDmaEnable.Value)
{
// This blink is used to signal the DMA that it should perform the peripheral -> memory transaction now
// Without this signal DMA will never move data from the receive buffer to memory
// See STM32DMA:OnGPIO
DMARecieve.Blink();
DMAReceive.Blink();
}
this.NoisyLog("Transmitted 0x{0:X}, received 0x{1:X}.", value, response);
}
Expand Down Expand Up @@ -175,7 +180,7 @@ private void SetupRegisters()
.WithFlag(8, name: "SSI") // Internal slave select
.WithFlag(9, name: "SSM") // Software slave management
.WithTaggedFlag("RXONLY", 10)
.WithTaggedFlag("DFF", 11)
.WithFlag(11, out data16Bit, name: "DFF")
.WithTaggedFlag("CRCNEXT", 12)
.WithTaggedFlag("CRCEN", 13)
.WithTaggedFlag("BIDIOE", 14)
Expand Down Expand Up @@ -248,7 +253,7 @@ private void SetupRegisters()
.WithReservedBits(10, 22);
}

private IFlagRegisterField txBufferEmptyInterruptEnable, rxBufferNotEmptyInterruptEnable, rxDmaEnable;
private IFlagRegisterField txBufferEmptyInterruptEnable, rxBufferNotEmptyInterruptEnable, rxDmaEnable, data16Bit;

private readonly DoubleWordRegisterCollection registers;

Expand Down