I can't figure out why it's not working. What am I doing wrong? I'm so confused.
Code: Select all
// DMA initialization procedure
procedure InitDMA;
begin
// 1. Enable DMA1 clock
RCC_AHBENR := EN_DMA1_CCR4_bit;
// 2. Configure DMA interrupts: TCIE (Transfer Complete), HTIE (Half Transfer), TEIE (Transfer Error)
TCIE_DMA1_CCR4_bit := 0;
HTIE_DMA1_CCR4_bit := 0;
TEIE_DMA1_CCR4_bit := 0;
// 3. Configure the source data transfer direction
// For example, if you're transmitting data from the memory to USART (TX), then:
DIR_DMA1_CCR4_bit := 1;
// Configure memory increment (memory address increment mode)
MINC_DMA1_CCR4_bit := 1;
// 4. Configure the channel priority
DMA1_CCR4 := (DMA1_CCR4 and not $00030000); // Set the priority (PL Bits 19:18) to 00 (Low priority)
// 5. Enable circular mode
CIRC_DMA1_CCR4_bit := 1;
PINC_DMA1_CCR4_bit := 0;
// 6. Configure memory and peripheral data sizes
PSIZE0_DMA1_CCR4_bit := 1; // Memory and peripheral data size: 8-bit
MEM2MEM_DMA1_CCR4_bit := 0;
// 7. Configure memory data size (MSIZE)
MSIZE0_DMA1_CCR4_bit := 1; // Memory data size: 8-bit
// 8. Configure the channel priority level
PL0_DMA1_CCR4_bit := 1;
// Enable the DMA channel
DMA1_CCR4 := DMA1_CCR4 or EN_DMA1_CCR4_bit;
end;
procedure SendTextWithDMA(var Text: string);
begin
// Copy the string to the buffer for transmission
CopyStringToBuffer(Text, TextBuffer);
// Enable DMA1 clock
RCC_AHBENR := RCC_AHBENR or DMA1EN_bit;
// Activate the DMA channel by setting the ENABLE bit in DMA1_CCR4
DMA1_CCR4 := DMA1_CCR4 or EN_DMA1_CCR4_bit;
// Configure DMA for USART1 data transmission (channel 4)
DMA1_CNDTR4 := Length(Text); // Set the number of data items to be transferred
DMA1_CMAR4 := dword(@TextBuffer[1]); // Set the memory address with data
DMA1_CPAR4 := dword(@USART1_DR); // Set the peripheral address (USART1_DR)
// Configure CCR (Control Register) for DMA1 channel 4
MINC_DMA1_CCR4_bit := 1;
PINC_DMA1_CCR4_bit := 1;
DIR_DMA1_CCR4_bit := 1;
// Enable the DMA channel
DMA1_CCR4 := DMA1_CCR4 or EN_DMA1_CCR4_bit;
// Wait for DMA to complete
while DMA1EN_bit <> 0 do;
// Disable USART1 transmission (if needed)
USART1_CR1 := USART1_CR1 and not TE;
end;
UART1_Init(115200);
InitDMA;