2020-06-18 01:01 AM
Hi I have a code bellow:
static void MX_UART8_Init(void)
{
/* USER CODE BEGIN UART8_Init 0 */
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN UART8_MspInit 0 */
/* USER CODE END UART8_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_UART8_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
/**UART8 GPIO Configuration
PE0 ------> UART8_RX
PE1 ------> UART8_TX
*/
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_UART8;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/* UART8 interrupt Init */
HAL_NVIC_SetPriority(UART8_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(UART8_IRQn);
/* USER CODE BEGIN UART8_MspInit 1 */
/* USER CODE END UART8_MspInit 1 */
/* USER CODE END UART8_Init 0 */
/* USER CODE BEGIN UART8_Init 1 */
/* USER CODE END UART8_Init 1 */
huart8.Instance = UART8;
huart8.Init.BaudRate = 9600;
huart8.Init.WordLength = UART_WORDLENGTH_8B;
huart8.Init.StopBits = UART_STOPBITS_1;
huart8.Init.Parity = UART_PARITY_NONE;
huart8.Init.Mode = UART_MODE_TX_RX;
huart8.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart8.Init.OverSampling = UART_OVERSAMPLING_16;
huart8.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart8.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart8) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN UART8_Init 2 */
/* USER CODE END UART8_Init 2 */
}
static void InitPPSAndStart(void)
{
/* EXTI interrupt init for PPS*/
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
HAL_NVIC_DisableIRQ(EXTI9_5_IRQn);
HAL_NVIC_ClearPendingIRQ(EXTI9_5_IRQn);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
}
static void ctrlMgrLMLoop(void) {
uint8_t statusFlag = 0;
uint32_t frameRate = 1;//226.5;
GPIO_PinState nx_arm_state;
uint8_t bcam_stream = 0;
int32_t i = 1;
/* stm trigger debug code start */
...
InitPPSAndStart();
MX_UART8_Init();
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1);
while(1)
{
Uartret = HAL_UART_Receive(&huart8, uartbuf, 1, HAL_MAX_DELAY); <---- Stuck HERE
if(uartIntCnt > 0)
{
/*process buffer*/
uartIntCnt--;
}
HAL_Delay(10);
}
...
}
By running the code it got stuck at :
Uartret = HAL_UART_Receive(&huart8, uartbuf, 1, HAL_MAX_DELAY);
By tracing deep into the code I will eventually come and wait here:
/**
* @brief Handle UART Communication Timeout.
* @param huart UART handle.
* @param Flag Specifies the UART flag to check
* @param Status Flag status (SET or RESET)
* @param Tickstart Tick start value
* @param Timeout Timeout duration
* @retval HAL status
*/
HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status,
uint32_t Tickstart, uint32_t Timeout)
{
/* Wait until flag is set */
while ((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status) <--- loop here
{
...
I have check the connection and the device, and I can see the device is giving out UART message, moreover the UART works on STM32F303-Nucleo-64 development board, my question is, is there any reason for the program to stall here ? and How can I debug futher ?
2020-06-18 06:51 PM
I think I figured out why, its due to the buffer management, as I set a breakpoint at UART receive the read buffer got overflow and cause the ORE to set.
however I am still not getting any interrupt from UART when I received any data from UART.