-1

我在使用 FreeRTOS 的 STM32F407 上遇到问题。到目前为止,发送到 xbee 模块的大部分消息都已发送。只有有时(5 到 60 分钟后)TX 过程会被中断。

在调试会话中,我可以看到,在 2 个字节(约 40 个)之后不再设置 TXEIE。UART_HandleTypeDef 的 TxXferCount 也是 42 (TxXferSize: 44)。SR-Register 中的标志 TXE 已设置,但 CR1-Register 中的 TXEIE 未设置。

ISR 激活了 2 次以将它们存储到数据/移位寄存器中。这我可以在逻辑分析仪上看到。但我无法弄清楚写作任务/isr的来源。

Xbee 模块获取消息并发送响应消息。感谢您的任何回复!

初始化:

GPIO_InitTypeDef GPIO_InitStruct;

__GPIOA_CLK_ENABLE();
__GPIOD_CLK_ENABLE();
__GPIOF_CLK_ENABLE();


/* RX-TX PIN */
GPIO_InitStruct.Pin = XBEE1_TX_PIN | XBEE1_RX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(XBEE1_TX_PORT, &GPIO_InitStruct);

/* Power*/
GPIO_InitStruct.Pin =  XBEE1_PWR_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(XBEE1_PWR_PORT, &GPIO_InitStruct);
HAL_GPIO_WritePin(XBEE1_PWR_PORT, XBEE1_PWR_PIN, GPIO_PIN_SET);

/* Reset PIN */
GPIO_InitStruct.Pin = XBEE1_RESET_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(XBEE1_RESET_PORT, &GPIO_InitStruct);

/* SLEEP_RQ PIN */
GPIO_InitStruct.Pin = XBEE1_SLEEP_RQ_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(XBEE1_SLEEP_RQ_PORT, &GPIO_InitStruct);



__USART2_CLK_ENABLE();

uart.Instance = USART2;
uart.Init.BaudRate = baud;
uart.Init.WordLength = UART_WORDLENGTH_8B;
uart.Init.StopBits = UART_STOPBITS_1;
uart.Init.Parity = UART_PARITY_NONE;
uart.Init.HwFlowCtl = UART_HWCONTROL_NONE;
uart.Init.Mode = UART_MODE_TX_RX;

if (HAL_UART_Init(&uart) != HAL_OK) {
    Error_Handler(XBEE1_ERROR);
}

//clear pending IRQs
__HAL_UART_CLEAR_FLAG(&uart, UART_FLAG_RXNE);
__HAL_UART_CLEAR_FLAG(&uart, USART_FLAG_TC);
__HAL_UART_CLEAR_FLAG(&uart, USART_FLAG_ORE);
__HAL_UART_CLEAR_FLAG(&uart, USART_FLAG_PE);
__HAL_UART_CLEAR_FLAG(&uart, USART_FLAG_FE);
__HAL_UART_CLEAR_FLAG(&uart, USART_FLAG_NE);
__HAL_UART_CLEAR_FLAG(&uart, USART_FLAG_TXE);

/* NVIC */
HAL_NVIC_SetPriority(USART2_IRQn, 6, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn);

传输

HAL_StatusTypeDef UART_Xbee1::send( uint8_t* pdata, size_t sz ) {
    return HAL_UART_Transmit_IT(&uart, pdata, sz);
}

情监侦

extern "C" void USART2_IRQHandler(void){
    testpin1.on();
    UART_HandleTypeDef* uart_c = &(Argos::xbee1->uart);
    uint32_t tmp1 = 0;
    uint32_t tmp2 = 0;
    tmp1 = __HAL_UART_GET_FLAG(uart_c, UART_FLAG_RXNE);
    tmp2 = __HAL_UART_GET_IT_SOURCE(uart_c, UART_IT_RXNE);
    if((tmp1 != RESET) && (tmp2 != RESET)){
        uint8_t in = (uint8_t)(uart_c->Instance->DR & (uint8_t)0x00FF);
        *uart_c->pRxBuffPtr++ = in;

        //overwrite expected bytes, when packet size is known
        if(xbee1->inApiRecMode){
            if( (uart_c->RxXferSize-uart_c->RxXferCount) == 1 ){
                xbee1->apiSize = 0;
                xbee1->apiSize = in << 8;
            }else if( (uart_c->RxXferSize-uart_c->RxXferCount) == 2 ){
                xbee1->apiSize |= in;
                uart_c->RxXferCount = xbee1->apiSize + 2;
            }
        }

        if( ((uart_c->RxXferCount)-1) == 0){
            (uart_c->RxXferCount)--;
              __HAL_UART_DISABLE_IT(uart_c, UART_IT_RXNE);

              /* Check if a transmit process is ongoing or not */
              if(uart_c->State == HAL_UART_STATE_BUSY_TX_RX){
                  uart_c->State   = HAL_UART_STATE_BUSY_TX;
              }else{
                /* Disable the UART Parity Error Interrupt */
                __HAL_UART_DISABLE_IT(uart_c, UART_IT_PE);

                /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
                __HAL_UART_DISABLE_IT(uart_c, UART_IT_ERR);

                uart_c->State = HAL_UART_STATE_READY;
              }

              Message* msg = &(xbee1->msg_callBack);
              msg->code = (uint8_t) XbeeContext::MessageType::RECEIVE_EVENT;
              msg->value = 0;
              xbee1->rcvCallback->sendMsg(msg);
            }else if( (uart_c->RxXferCount) == 0){
                Error_Handler(XBEE1_ERROR);
            }else{
                (uart_c->RxXferCount)--;
            }
    }else{

        //other cases
        HAL_UART_IRQHandler( uart_c );
    }
    testpin1.off();
}
4

1 回答 1

0

这个 isr 处理程序代码来自哪里?它看起来与 stm32f4 HAL 1.8 中的内容没有任何相似之处?

如果您使用 hal,最好将您的 irq 处理程序链接到 hal 并定义对托管错误和完成的回调。

HAL_UART_TxCpltCallback HAL_UART_RxCpltCallback HAL_UART_ErrorCallback

于 2015-11-05T22:24:49.923 回答