DMA buffer Question
I am trying to send large streams of data into the STM32H753 and I'm trying to maximize the baud rate, ideally aiming for a baud rate of 921600. Unfortunately, I don't know the byte size that will be incoming, which makes it difficult to know how to handle this. I currently have it setup to handle one byte at a time, which isn't very efficient.
Below is essentially what I'm using:
#define uartsize 2000
#define dma_buffer_interrupt_size 1
char UART_out_Buffer[100];
uint8_t UART_in_Buffer[uartsize];
int8_t buf_len = 0;
uint8_t in_byte;
uint32_t head_index = 0;
uint32_t tail_index = 0;
int main(void)
{
HAL_Init();
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ETH_Init();
MX_USART3_UART_Init();
MX_DMA_Init();
MX_USB_OTG_FS_PCD_Init();
buf_len = sprintf(UART_out_Buffer, "Hello World\r\n");
HAL_UART_Transmit(&huart3, (uint8_t *)UART_out_Buffer, buf_len, 100);
HAL_UART_Receive_DMA(&huart3, &UART_in_Buffer[head_index], dma_buffer_interrupt_size);
while (1)
{
}
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
head_index = (head_index + dma_buffer_interrupt_size) % uartsize;
HAL_UART_Receive_DMA(&huart3, &UART_in_Buffer[head_index], dma_buffer_interrupt_size);
}Below is my peripheral setup:
static void MX_USART3_UART_Init(void)
{
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart3) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK)
{
Error_Handler();
}
}
static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Stream0_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);
}This works fine at 115200 but it won't work at 921600. I decided to try changing the size of the interrupt so I could shift in, say, 10 bytes at a time from the DMA rather than just one but this essentially lead me to getting the first of the 10 bytes stored into my uart buffer and missing the next 10 and did that throughout the transmission (so if I sent 1k bytes, it would get the first byte, I'd get 9 0's and then repeat this all the way through 1000 bytes of the UART buffer). This makes me lead towards me potentially having the buffer setup incorrectly if it's not actually filling the buffer like I would expect it to.
Not sure if anyone can give me some insight on what my issue might be or how I can get around this. I think I'm close but I'm missing something important.
I'm currently running the system clock at 240 MHz and the UART clock is at 75 MHz, if that helps.