Question
[STM32F401][HAL][UART DMA][QnA]
Hey folks, I am using UART RX in DMA mode using 512 byte buffer. My code sippest working fine. I have one question.
Q. Suppose you have recevied 12 bytes but you have set 512 length so, rxCmplt() callback will not called. Right? But I wanted to stop UART RX DMA and don't wanted to waste this 12 bytes also. How I can archive this?
#include "main.h"
uint8_t UART1_rxBuffer[512] = {0};
UART_HandleTypeDef huart1;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
HAL_UART_Receive_DMA (&huart1, UART1_rxBuffer, 12);
while (1)
{
if(BTN()){
// I want to stop manually and read received data.
// Assume that 5 bytes in DMA to read.
HAL_UART_Abort();
}
}
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Transmit(&huart1, UART1_rxBuffer, 512, 100);
HAL_UART_Receive_DMA(&huart1, UART1_rxBuffer, 512);
}
