2020-01-12 08:49 AM
my problem is that the DMA only writes to the first address of the buffer,
means that when i look on the buffer, the last byte of the message is stored in the first place of the array, and the rest of the data is overwritten.
what could be the problem, what am i missing?
/* USER CODE BEGIN 2 */
__HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE); // enable idle line interrupt
HAL_UART_Receive_DMA(&huart2, rxBuf, 255);
//__HAL_DMA_ENABLE_IT (&hdma_usart2_rx, DMA_IT_TC);
/* USER CODE END 2 */
/**
* @brief This function handles USART2 global interrupt.
*/
void USART2_IRQHandler(void)
{
/* USER CODE BEGIN USART2_IRQn 0 */
/* USER CODE END USART2_IRQn 0 */
HAL_UART_IRQHandler(&huart2);
/* USER CODE BEGIN USART2_IRQn 1 */
if(RESET != __HAL_UART_GET_FLAG(&huart2, UART_FLAG_IDLE)) //Judging whether it is idle interruption
{
__HAL_UART_CLEAR_IDLEFLAG(&huart2); //Clear idle interrupt sign (otherwise it will continue to enter interrupt)
printf("UART2 Idle IQR Detected\r\n");
HAL_UART_DMAStop(&huart2);
//__HAL_DMA_DISABLE (&hdma_usart2_rx);
uint8_t data_length = 255 - __HAL_DMA_GET_COUNTER(&hdma_usart2_rx);
printf("Receive Data(length = %d): ",data_length);
HAL_UART_Transmit(&huart2,rxBuf,data_length,0x200);
printf("\r\n");
//memset(receive_buff,0,data_length);
HAL_UART_Receive_DMA(&huart2, rxBuf, 255);
}
/* USER CODE END USART2_IRQn 1 */
2020-01-12 09:10 AM
The HAL_UART_IRQHandler() will call your call-back routines.
You should definitely avoid blocking HAL_UART_Transmit() function and printf() in the IRQ Handler or call-back routines.
There are significantly cleaner and more efficient approaches to IRQ/DMA than those used by the HAL implementation
2020-01-13 02:14 AM
Hi. Have you configure DMA with destination address increment by byte?
2020-01-13 02:40 AM
yup
2020-01-13 03:32 AM
New to ST, start simpler, get it working with IRQ, the thing interrupts with every byte, for variable sized packets use a state machine to determine size and packetize to processing task. Assuming someone thought out the protocols so it doesn't need inter-message gaps to demux.