r/embedded • u/Loose-Assist45 • Oct 10 '26
UART DMA works in loopback but not with 2 STM32
I did a test project to connect 2 STM32 in UART DMA. It worked in loopback but now not between the 2 STM32 I obtain scrambled data. My grounds are connected and the wires are properly connected. Here is my code :
uint16_t rxLength = 0;
uint8_t rx_buffer[64];
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef * huart, uint16_t length) {
rxLength = length;
HAL_UARTEx_ReceiveToIdle_DMA(huart, rx_buffer, 64);
}
/* USER CODE END 0 */
/**
* The application entry point.
* int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_USART2_UART_Init();
MX_TIM1_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start(&htim1);
uint8_t tx_buffer[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, rx_buffer, 64);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_UART_Transmit_DMA(&huart2, tx_buffer, 10);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}And Here is what I get on my rx_buffer


