在为包含FT2232H UART < - > USB转换器的自定义STM32F7板设置项目后,我在发送(和接收数据)时遇到了多个问题。我使用的代码主要由CubeMX生成,位于帖子的末尾。首先,根据数据表,FT2232H和STM32F7的波特率至少应为12M波特,我无法让波特率高于标准115200。对于FT2232H,我正在工作,因为我从终端(USB端)发送一些字符,并在我短接FT2232H输出端的RX和TX引脚时收回了字符。其次是我不能连续多次调用sendUART()函数,为什么DMA Fifo不用于存储我想要发送的东西?还有什么方法可以回显所有收到的数据,但是利用了fifo,这样当没有及时轮询数据时,没有数据丢失?- void MX_UART4_Init(void)
- {
- huart4.Instance = UART4;
- huart4.Init.BaudRate = 115200;
- huart4.Init.WordLength = UART_WORDLENGTH_8B;
- huart4.Init.StopBits = UART_STOPBITS_1;
- huart4.Init.Parity = UART_PARITY_NONE;
- huart4.Init.Mode = UART_MODE_TX_RX;
- huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart4.Init.OverSampling = UART_OVERSAMPLING_16;
- huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
- huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
- if (HAL_UART_Init(&huart4) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- }
- void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- if(uartHandle->Instance==UART4)
- {
- /* USER CODE BEGIN UART4_MspInit 0 */
- /* USER CODE END UART4_MspInit 0 */
- /* UART4 clock enable */
- __HAL_RCC_UART4_CLK_ENABLE();
- /**UART4 GPIO Configuration
- PA0/WKUP ------> UART4_TX
- PA1 ------> UART4_RX
- */
- GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF8_UART4;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- /* UART4 DMA Init */
- /* UART4_TX Init */
- hdma_uart4_tx.Instance = DMA1_Stream4;
- hdma_uart4_tx.Init.Channel = DMA_CHANNEL_4;
- hdma_uart4_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
- hdma_uart4_tx.Init.PeriphInc = DMA_PINC_DISABLE;
- hdma_uart4_tx.Init.MemInc = DMA_MINC_ENABLE;
- hdma_uart4_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
- hdma_uart4_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
- hdma_uart4_tx.Init.Mode = DMA_NORMAL;
- hdma_uart4_tx.Init.Priority = DMA_PRIORITY_MEDIUM;
- hdma_uart4_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
- hdma_uart4_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
- hdma_uart4_tx.Init.MemBurst = DMA_MBURST_SINGLE;
- hdma_uart4_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
- if (HAL_DMA_Init(&hdma_uart4_tx) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- __HAL_LINKDMA(uartHandle,hdmatx,hdma_uart4_tx);
- /* UART4_RX Init */
- hdma_uart4_rx.Instance = DMA1_Stream2;
- hdma_uart4_rx.Init.Channel = DMA_CHANNEL_4;
- hdma_uart4_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
- hdma_uart4_rx.Init.PeriphInc = DMA_PINC_DISABLE;
- hdma_uart4_rx.Init.MemInc = DMA_MINC_ENABLE;
- hdma_uart4_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
- hdma_uart4_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
- hdma_uart4_rx.Init.Mode = DMA_NORMAL;
- hdma_uart4_rx.Init.Priority = DMA_PRIORITY_MEDIUM;
- hdma_uart4_rx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
- hdma_uart4_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
- hdma_uart4_rx.Init.MemBurst = DMA_MBURST_SINGLE;
- hdma_uart4_rx.Init.PeriphBurst = DMA_PBURST_SINGLE;
- if (HAL_DMA_Init(&hdma_uart4_rx) != HAL_OK)
- {
- _Error_Handler(__FILE__, __LINE__);
- }
- __HAL_LINKDMA(uartHandle,hdmarx,hdma_uart4_rx);
- /* USER CODE BEGIN UART4_MspInit 1 */
- /* USER CODE END UART4_MspInit 1 */
- }
- }
- void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
- {
- if(uartHandle->Instance==UART4)
- {
- /* USER CODE BEGIN UART4_MspDeInit 0 */
- /* USER CODE END UART4_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_UART4_CLK_DISABLE();
- /**UART4 GPIO Configuration
- PA0/WKUP ------> UART4_TX
- PA1 ------> UART4_RX
- */
- HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1);
- /* UART4 DMA DeInit */
- HAL_DMA_DeInit(uartHandle->hdmatx);
- HAL_DMA_DeInit(uartHandle->hdmarx);
- /* USER CODE BEGIN UART4_MspDeInit 1 */
- /* USER CODE END UART4_MspDeInit 1 */
- }
- }
- /* USER CODE BEGIN 1 */
- void sendUART(char msg[]){
- //HAL_UART_Transmit(&huart4,(uint8_t *) msg, strlen(msg),10000);
- HAL_UART_Transmit_DMA(&huart4,(uint8_t *) msg, strlen(msg));
- }
- void echo(){
- if(HAL_UART_Receive_DMA(&huart4, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK){}
- else if(HAL_UART_Transmit_DMA(&huart4, (uint8_t*)aRxBuffer, RXBUFFERSIZE)!= HAL_OK){
- }
- }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>