2019-10-17 05:47 AM
I have implemented an emulated UART on STM32F2 using the sample program from STM32F4. The UART TX data output is correct. Until a HAL_Delay(100) is add. When added delay, the UART TX output appears corrupted as shown below. Why is the HAL_Delay affecting the UART TX data? I have attached the whole project.
2019-10-28 06:05 PM
Hi just to add on, I am sending abcd in ascii and the HAL_Delay(100) caused weird ascii text to appear too. The data seems to be corrupted due to the delay. But if I remove the delay, the data is received correctly.
2019-10-28 06:25 PM
Where are you calling HAL_Delay() from? Calling under interrupt/callback context will block, potentially any other interrupts at current preemption level and below (higher number)
2019-10-28 07:09 PM
I am calling it right after the while loop.
while (1)
{
HAL_Delay(100);
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
LED_State = HAL_GPIO_ReadPin(LD2_GPIO_Port, LD2_Pin);
HAL_UART_Emul_Transmit_DMA(&huart3Tx, tx_buffer_uart3, sizeof(tx_buffer_uart3));
while (__HAL_UART_EMUL_GET_FLAG(&huart3Tx, UART_EMUL_FLAG_TC) != SET)
}
2019-10-29 12:23 AM
Where is the ";" after the while() ?
Compiler should provide a warning or the copy paste didn't work?
2019-10-29 01:04 AM
My apologize, when I copy it over to this forum, I miss out the {}. In the actual code there is {} after the while() as shown below.
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_ETH_Init();
MX_USB_OTG_FS_PCD_Init();
MX_TIM1_Init();
MX_USART3_UART_Init();
/* USER CODE BEGIN 2 */
MX_USART3_UART_Emul_Init();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_Delay(100);
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
LED_State = HAL_GPIO_ReadPin(LD2_GPIO_Port, LD2_Pin);
HAL_UART_Emul_Transmit_DMA(&huart3Tx, tx_buffer_uart3, sizeof(tx_buffer_uart3));
while (__HAL_UART_EMUL_GET_FLAG(&huart3Tx, UART_EMUL_FLAG_TC) != SET)
{}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}