0

I want to control my corresponding infrared signal emission through my USART input command, use num to refer to, flag indicates whether the USART controls the emission

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    UNUSED(huart);
    if(Uart1_Rx_Cnt >= 255) //overflow judgment
    {
       memset(RxBuffer, 0x00, sizeof(RxBuffer));
       HAL_UART_Transmit(&huart1,(uint8_t *)"data overflow", 10, HAL_MAX_DELAY);
    
    }else
    {
        RxBuffer[Uart1_Rx_Cnt++] = aRxBuffer; //Receive data dump
        if((RxBuffer[Uart1_Rx_Cnt - 1] == 0x0A) && (RxBuffer[Uart1_Rx_Cnt - 2] == 0x0D)) //Judge the end bit
        {
            num = (RxBuffer[0] - '0') * 10 + RxBuffer[1] - '0';
            
            char* message = NULL;
            if(num > index || num < 1) {
            
              message = "The current number is beyond the latest storage offset range\r\n";
              HAL_UART_Transmit(&huart1,(uint8_t*)message, strlen(message), HAL_MAX_DELAY);
              Error_Handler();
              
            } else {
            
              flag = 0;
            
            }
              
            HAL_UART_Transmit(&huart1,(uint8_t *)&RxBuffer, Uart1_Rx_Cnt, HAL_MAX_DELAY); //Send the received message
            while(HAL_UART_GetState(&huart1) == HAL_UART_STATE_BUSY_TX); //Detect the end of UART transmission
            Uart1_Rx_Cnt = 0;
            memset(RxBuffer, 0x00, sizeof(RxBuffer)); //clear the array
        }
    
    }
    
    HAL_UART_Receive_IT(&huart1,(uint8_t *)&aRxBuffer, 1); //Enable receive interrupt again
}

But a dramatic scene happened. My freeRTOS task was normal when I didn’t do any serial communication, but my StartKeyControlTask crashed after performing the communication.

void StartKeyControlTask(void const * argument)
{
  /* USER CODE BEGIN StartKeyControlTask */
  uint8_t bykey = 0;
  /* Infinite loop */
  for(;;)
  {
    while(HAL_UART_GetState(&huart1) == HAL_UART_STATE_BUSY);   //检测UART发送结束
    if(HAL_GPIO_ReadPin(learn_GPIO_Port, learn_Pin) == GPIO_PIN_SET) {
//      osDelay(10);
      if(HAL_GPIO_ReadPin(learn_GPIO_Port, learn_Pin) == GPIO_PIN_SET) {
        bykey = 1;
        osMessagePut(keyCodeQueueHandle,bykey,0);//向队列发送一个学习消息
        while(HAL_GPIO_ReadPin(learn_GPIO_Port, learn_Pin) == GPIO_PIN_SET);
      }
    }
    if(HAL_GPIO_ReadPin(send_GPIO_Port, send_Pin) == GPIO_PIN_SET) {
//      osDelay(10);
      if(HAL_GPIO_ReadPin(send_GPIO_Port, send_Pin) == GPIO_PIN_SET) {
        bykey = 2;
        osMessagePut(keyCodeQueueHandle,bykey,0);//向队列发送一个发射消息
        while(HAL_GPIO_ReadPin(send_GPIO_Port, send_Pin) == GPIO_PIN_SET);
      }
    }
    osDelay(1);
  }
  /* USER CODE END StartKeyControlTask */
}

Where the crash happens is at`osMessagePut(keyCodeQueueHandle,bykey,0);The exception stack information is

  • HardFault_Handler
  • [__iar_small_Memcpy + 0x3]
  • memcpy ***
  • xQueueGenericSend
  • osMessagePut
  • StartKeyControlTask
  • prvTaskExitError

I have tried adjusting the highest priority of USART and freeRTOS, and tried to make USART a higher priority, but it seems to be of no use. Also try to add a sentence while(HAL_UART_GetState(&huart1) == HAL_UART_STATE_BUSY); //Detecting the end of UART transmission in StartKeyControlTask has no effect

KunBoy5240
  • 11
  • 1

0 Answers0