I am working with STM32F103RB board and I want to simply echo everything I receive from my computer via serial port back to that port. I must do it using UART and DMA. I've set up DMA on USART2_RX with CubeMX in normal mode. My problem is that HAL_UART_RxCpltCallback
gets called only once. Interestingly I get the response on PC end but with additional 0xFC
byte. After that the controller stops reacting to new data sent through the serial port and won't do so until I unplug and plug controller back in with usb. Here is the code for call back and main function:
#define BUF_SIZE 16
uint8_t RX_BUF[BUF_SIZE] = {0};
uint8_t TX_BUF[BUF_SIZE] = {0};
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Transmit(&huart2, RX_BUF, BUF_SIZE, 1000);
HAL_UART_Receive_DMA(&huart2, RX_BUF, BUF_SIZE);
}
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();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_DMA(&huart2, RX_BUF, sizeof (RX_BUF));
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
Edit: I am trying to do this on a Mac through USB-C dongle. Can this be the problem?