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.
49 lines
1.7 KiB
49 lines
1.7 KiB
#pragma once
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
|
|
#include "stm32basic/stm32basic.hpp"
|
|
#include "stm32halport/stm32halport.hpp"
|
|
|
|
namespace iflytop {
|
|
|
|
class HalUtils {
|
|
public:
|
|
static void uartdmainit(UART_HandleTypeDef* uart, DMA_HandleTypeDef* rxdma, uint32_t rxdmach, DMA_HandleTypeDef* txdma, uint32_t txdmach) {
|
|
rxdma->Instance = getDmaStreamTypeDef(rxdma);
|
|
rxdma->Init.Channel = rxdmach;
|
|
rxdma->Init.Direction = DMA_PERIPH_TO_MEMORY;
|
|
rxdma->Init.PeriphInc = DMA_PINC_DISABLE;
|
|
rxdma->Init.MemInc = DMA_MINC_ENABLE;
|
|
rxdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
|
rxdma->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
|
rxdma->Init.Mode = DMA_NORMAL;
|
|
rxdma->Init.Priority = DMA_PRIORITY_LOW;
|
|
rxdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
|
|
ZASSERT(rxdma->Instance);
|
|
if (HAL_DMA_Init(rxdma) != HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
|
|
__HAL_LINKDMA(uart, hdmarx, *rxdma);
|
|
|
|
txdma->Instance = getDmaStreamTypeDef(txdma);
|
|
txdma->Init.Channel = txdmach;
|
|
txdma->Init.Direction = DMA_MEMORY_TO_PERIPH;
|
|
txdma->Init.PeriphInc = DMA_PINC_DISABLE;
|
|
txdma->Init.MemInc = DMA_MINC_ENABLE;
|
|
txdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
|
txdma->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
|
txdma->Init.Mode = DMA_NORMAL;
|
|
txdma->Init.Priority = DMA_PRIORITY_LOW;
|
|
txdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
|
|
ZASSERT(rxdma->Instance);
|
|
if (HAL_DMA_Init(txdma) != HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
|
|
__HAL_LINKDMA(uart, hdmatx, *txdma);
|
|
}
|
|
};
|
|
|
|
} // namespace iflytop
|