Advertisement
Guest User

Untitled

a guest
May 4th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. In stm32_xx_it , I added these lines :
  2. void USARTx_DMA_RX_IRQHandler(void) {
  3. HAL_DMA_IRQHandler(UartMsgHandle.hdmarx);
  4. }
  5.  
  6.  
  7. void USARTx_DMA_TX_IRQHandler(void) {
  8. HAL_DMA_IRQHandler(UartMsgHandle.hdmatx);
  9. }
  10.  
  11.  
  12. void USARTx_IRQHandler(void) {
  13. HAL_UART_IRQHandler(&UartMsgHandle);
  14. }
  15.  
  16. And in another file normally ,i changed the hal msp init and deinit like this :
  17.  
  18. void HAL_UART_MspInit(UART_HandleTypeDef *huart) {
  19. static DMA_HandleTypeDef hdma_tx;
  20. static DMA_HandleTypeDef hdma_rx;
  21.  
  22. GPIO_InitTypeDef GPIO_InitStruct;
  23.  
  24. /*##-1- Enable peripherals and GPIO Clocks #################################*/
  25. /* Enable GPIO clock */
  26. USARTx_TX_GPIO_CLK_ENABLE()
  27. ;
  28. USARTx_RX_GPIO_CLK_ENABLE()
  29. ;
  30. /* Enable USART1 clock */
  31. USARTx_CLK_ENABLE()
  32. ;
  33. /* Enable DMA1 clock */
  34. __HAL_RCC_DMA1_CLK_ENABLE()
  35. ;
  36. /*##-2- Configure peripheral GPIO ##########################################*/
  37. /* UART TX GPIO pin configuration */
  38. GPIO_InitStruct.Pin = WiFi_USART_PRINT_TX_PIN;
  39. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  40. GPIO_InitStruct.Pull = GPIO_PULLUP;
  41. GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  42. GPIO_InitStruct.Alternate = PRINTMSG_USARTx_TX_AF;
  43.  
  44. HAL_GPIO_Init(WiFi_USART_PRINT_TX_GPIO_PORT, &GPIO_InitStruct);
  45.  
  46. /* UART RX GPIO pin configuration */
  47. GPIO_InitStruct.Pin = WiFi_USART_PRINT_RX_PIN;
  48. GPIO_InitStruct.Alternate = PRINTMSG_USARTx_RX_AF;
  49.  
  50. HAL_GPIO_Init(WiFi_USART_PRINT_RX_GPIO_PORT, &GPIO_InitStruct);
  51.  
  52. /*##-3- Configure the DMA streams ##########################################*/
  53. /* Configure the DMA handler for Transmission process */
  54. hdma_tx.Instance = DMA1_Stream6;
  55.  
  56. hdma_tx.Init.Channel = DMA_CHANNEL_4;
  57. hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
  58. hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE;
  59. hdma_tx.Init.MemInc = DMA_MINC_ENABLE;
  60. hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  61. hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  62. hdma_tx.Init.Mode = DMA_NORMAL;
  63. hdma_tx.Init.Priority = DMA_PRIORITY_LOW;
  64. hdma_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
  65. hdma_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
  66. hdma_tx.Init.MemBurst = DMA_MBURST_INC4;
  67. hdma_tx.Init.PeriphBurst = DMA_PBURST_INC4;
  68.  
  69. HAL_DMA_Init(&hdma_tx);
  70.  
  71. /* Associate the initialized DMA handle to the UART handle */
  72. __HAL_LINKDMA(huart, hdmatx, hdma_tx);
  73.  
  74. /* Configure the DMA handler for reception process */
  75. hdma_rx.Instance = DMA1_Stream5;
  76.  
  77. hdma_rx.Init.Channel = DMA_CHANNEL_4;
  78. hdma_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
  79. hdma_rx.Init.PeriphInc = DMA_PINC_DISABLE;
  80. hdma_rx.Init.MemInc = DMA_MINC_ENABLE;
  81. hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  82. hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  83. hdma_rx.Init.Mode = DMA_NORMAL;
  84. hdma_rx.Init.Priority = DMA_PRIORITY_HIGH;
  85. hdma_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
  86. hdma_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
  87. hdma_rx.Init.MemBurst = DMA_MBURST_INC4;
  88. hdma_rx.Init.PeriphBurst = DMA_PBURST_INC4;
  89.  
  90. HAL_DMA_Init(&hdma_rx);
  91.  
  92. /* Associate the initialized DMA handle to the the UART handle */
  93. __HAL_LINKDMA(huart, hdmarx, hdma_rx);
  94.  
  95. /*##-4- Configure the NVIC for DMA #########################################*/
  96. /* NVIC configuration for DMA transfer complete interrupt (USARTx_TX) */
  97. HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0, 1);
  98. HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn);
  99.  
  100. /* NVIC configuration for DMA transfer complete interrupt (USARTx_RX) */
  101. HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 0, 0);
  102. HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn);
  103.  
  104. /* NVIC configuration for USART TC interrupt */
  105. HAL_NVIC_SetPriority(USARTx_IRQn, 0, 0);
  106. HAL_NVIC_EnableIRQ(USARTx_IRQn);
  107. }
  108.  
  109. /**
  110. * @brief UART MSP De-Initialization
  111. * This function frees the hardware resources used in this example:
  112. * - Disable the Peripheral's clock
  113. * - Revert GPIO, DMA and NVIC configuration to their default state
  114. * @param huart: UART handle pointer
  115. * @retval None
  116. */
  117. void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) {
  118.  
  119. //static DMA_HandleTypeDef hdma_tx;
  120. //static DMA_HandleTypeDef hdma_rx;
  121. if (huart == &UartWiFiHandle) {
  122. USARTx_FORCE_RESET();
  123. USARTx_RELEASE_RESET();
  124.  
  125. HAL_GPIO_DeInit(WiFi_USART_TX_GPIO_PORT, WiFi_USART_TX_PIN);
  126. HAL_GPIO_DeInit(WiFi_USART_RX_GPIO_PORT, WiFi_USART_RX_PIN);
  127. //HAL_DMA_DeInit(&hdma_tx);
  128. /* De-Initialize the DMA Stream associate to reception process */
  129. //HAL_DMA_DeInit(&hdma_rx);
  130. /*##-4- Disable the NVIC for DMA ###########################################*/
  131. HAL_NVIC_DisableIRQ(DMA2_Stream6_IRQn);
  132. HAL_NVIC_DisableIRQ(DMA2_Stream5_IRQn);
  133. HAL_NVIC_DisableIRQ(USARTx_IRQn);
  134.  
  135. /*##-3- Disable the DMA Streams ############################################*/
  136. /* De-Initialize the DMA Stream associate to transmission process */
  137.  
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement