全司美特-单片机程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.7 KiB

1 year ago
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include "zsdk/zsdk.hpp"
  5. #include "zstm32/zstm32.hpp"
  6. namespace iflytop {
  7. class HalUtils {
  8. public:
  9. static void uartdmainit(UART_HandleTypeDef* uart, DMA_HandleTypeDef* txdma, uint32_t txdmach, DMA_HandleTypeDef* rxdma, uint32_t rxdmach) {
  10. /* USART2 DMA Init */
  11. /* USART2_RX Init */
  12. rxdma->Instance = getDmaStreamTypeDef(rxdma);
  13. rxdma->Init.Channel = rxdmach;
  14. rxdma->Init.Direction = DMA_PERIPH_TO_MEMORY;
  15. rxdma->Init.PeriphInc = DMA_PINC_DISABLE;
  16. rxdma->Init.MemInc = DMA_MINC_ENABLE;
  17. rxdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  18. rxdma->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  19. rxdma->Init.Mode = DMA_NORMAL;
  20. rxdma->Init.Priority = DMA_PRIORITY_LOW;
  21. rxdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
  22. if (HAL_DMA_Init(rxdma) != HAL_OK) {
  23. Error_Handler();
  24. }
  25. __HAL_LINKDMA(uart, hdmarx, *rxdma);
  26. /* USART2_TX Init */
  27. txdma->Instance = getDmaStreamTypeDef(txdma);
  28. txdma->Init.Channel = txdmach;
  29. txdma->Init.Direction = DMA_MEMORY_TO_PERIPH;
  30. txdma->Init.PeriphInc = DMA_PINC_DISABLE;
  31. txdma->Init.MemInc = DMA_MINC_ENABLE;
  32. txdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
  33. txdma->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
  34. txdma->Init.Mode = DMA_NORMAL;
  35. txdma->Init.Priority = DMA_PRIORITY_LOW;
  36. txdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
  37. if (HAL_DMA_Init(txdma) != HAL_OK) {
  38. Error_Handler();
  39. }
  40. __HAL_LINKDMA(uart, hdmatx, *txdma);
  41. }
  42. };
  43. } // namespace iflytop