Today, I encountered a tricky problem while debugging. I would like to share the solution with you. I use the HAL library, a rotten library that drives me crazy. I want to curse at it, but I can't get rid of my anger no matter how much I curse at it. Serial port + DMA, the DMA routine of the official website 407 is transplanted, no need for too much explanation, just put the code void HAL_UART_MspInit(UART_HandleTypeDef* huart) { GPIO_InitTypeDef GPIO_InitStruct; if(huart->Instance==USART3) { /* USER CODE BEGIN USART3_MspInit 0 */ /* USER CODE END USART3_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_USART3_CLK_ENABLE(); /**USART3 GPIO Configura on /** PB10 ------> USART3_TX PB11 ------> USART3_RX */ GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF7_USART3; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /*##-3- Configure the DMA streams ##############################################*/ /* Configure the DMA handler for Transmission process */ hdma_usart3_tx.Instance = USARTx_TX_DMA_STREAM; hdma_usart3_tx.Init.Channel = USARTx_TX_DMA_CHANNEL; hdma_usart3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_usart3_tx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_usart3_tx.Init.MemInc = DMA_MINC_ENABLE; hdma_usart3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; hdma_usart3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; hdma_usart3_tx.Init.Mode = DMA_NORMAL; hdma_usart3_tx.Init.Priority = DMA_PRIORITY_LOW; hdma_usart3_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; hdma_usart3_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; hdma_usart3_tx.Init.MemBurst = DMA_MBURST_INC4; hdma_usart3_tx.Init.PeriphBurst = DMA_PBURST_INC4; HAL_DMA_Init(&hdma_usart3_tx); /* Associate the initialized DMA handle to the UART handle */ __HAL_LINKDMA(huart, hdmatx, /* Associate the initialized DMA handle to the the UART handle */ __HAL_LINKDMA(huart, hdmarx, hdma_usart3_rx); /*##-4- Configure the NVIC for DMA ############################################*/ /* NVIC configuration for DMA transfer complete interrupt (USARTx_TX) */ HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 0, 1); HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn); /* USER CODE BEGIN USART3_MspInit 1 */ HAL_NVIC_SetPriority(USART3_IRQn, 0,0); HAL_NVIC_EnableIRQ(USART3_IRQn); /* USER CODE END USART3_MspInit 1 */ } } /* USART3 init function */static void MX_USART3_UART_Init(void){ huart3.Instance = USART3; huart3.Init.BaudRate = 115200*2; huart3.Init.WordLength = UART_WORDLENGTH_8B; huart3.Init.StopBits = UART_STOPBITS_1; huart3.Init.Parity = UART_PARITY_NONE; huart3.Init.Mode = UART_MODE_TX_RX; huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart3.Init.OverSampling = UART_OVERSAMPLING_16; if (HAL_UART_Init(&huart3) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } } The above is the initialization code DMA sending, interrupt receiving, The serial port is communicating with the 4G module. I won’t tell you which manufacturer it is from. I can only say it is very low-end. When configuring the module, the following figure appears:
There is no error after powering on again. I connected the serial port of f4 and started debugging. Suddenly, I was shocked. I kept entering the serial port interruption. When I single-stepped, I saw Framing error at first, then Noise detected flag, Overrun These two errors are equivalent to entering an endless loop. I was so anxious that I cursed my mother. I searched Baidu, but basically got nothing. I knew it was a hardware problem, so I turned on the oscilloscope and found that the waveform was indeed problematic. The serial port of f4 was debugged many times using the serial port assistant, and there must be no problem. I could only lower the baud rate of the 4G module by one level, because I had used 115200 (factory default value) without any problems before. Sure enough, there was no problem. I raised the baud rate to 230400 again until there were no errors in the debugging software and repeated tests were OK. Sure enough, everything was normal. I just treated it as a water post to share my experience with everyone. This content is original by star_66666, a netizen of EEWORLD forum. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source__LINE__); } } The above is the initialization code DMA sending, interrupt receiving, The serial port is communicating with the 4G module. I won’t tell you which manufacturer it is from. I can only say it is very low-end. When configuring the module, the following figure appears:
There is no error after powering on again. I connected the serial port of f4 and started debugging. Suddenly, I was shocked. I kept entering the serial port interruption. When I single-stepped, I saw Framing error at first, then Noise detected flag, Overrun These two errors are equivalent to entering an endless loop. I was so anxious that I cursed my mother. I searched Baidu, but basically got nothing. I knew it was a hardware problem, so I turned on the oscilloscope and found that the waveform was indeed problematic. The serial port of f4 was debugged many times using the serial port assistant, and there must be no problem. I could only lower the baud rate of the 4G module by one level, because I had used 115200 (factory default value) without any problems before. Sure enough, there was no problem. I raised the baud rate to 230400 again until there were no errors in the debugging software and repeated tests were OK. Sure enough, everything was normal. I just treated it as a water post to share my experience with everyone. This content is original by star_66666, a netizen of EEWORLD forum. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source
So what are you explaining? If you keep entering interrupts, it's because you have enabled many control registers, which makes the event always valid. HAL itself is that one interrupt function includes everything for you, which is also inconvenient. But you can make a function interrupt interface yourself and only enable the interrupt trigger you want.
Details
Published on 2018-12-11 10:37
So what are you explaining? If you keep entering interrupts, it's because you have enabled many control registers, which makes the event always valid. HAL itself is that one interrupt function includes everything for you, which is also inconvenient. But you can make a function interrupt interface yourself and only enable the interrupt trigger you want.