Files
@ 21759af9d2ad
Branch filter:
Location: FeatherHAB/wsprhab/src/uart.c - annotation
21759af9d2ad
3.2 KiB
text/plain
Various changes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 | #include "stm32f0xx_hal.h"
#include "uart.h"
#include "config.h"
#include "gpio.h"
UART_HandleTypeDef huart1;
DMA_HandleTypeDef hdma_usart1_rx;
DMA_HandleTypeDef hdma_usart1_tx;
uint8_t uart_initted = 0;
void uart_init(void)
{
__GPIOB_CLK_ENABLE();
__HAL_RCC_USART1_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
// Init gpio pins for uart
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL; //GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_USART1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
// Init UART periph
huart1.Instance = USART1;
huart1.Init.BaudRate = 9600;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT|UART_ADVFEATURE_DMADISABLEONERROR_INIT;
huart1.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;
huart1.AdvancedInit.DMADisableonRxError = UART_ADVFEATURE_DMA_DISABLEONRXERROR;
HAL_UART_Init(&huart1);
//
// __DMA1_CLK_ENABLE();
//
// // Init UART DMA
// hdma_usart1_rx.Instance = DMA1_Channel3;
// hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
// hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
// hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
// hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
// hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
// hdma_usart1_rx.Init.Mode = DMA_CIRCULAR;
// hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;
// HAL_DMA_Init(&hdma_usart1_rx);
//
// __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx);
//
// hdma_usart1_tx.Instance = DMA1_Channel2;
// hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
// hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
// hdma_usart1_tx.Init.MemInc = DMA_MINC_DISABLE;
// hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
// hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
// hdma_usart1_tx.Init.Mode = DMA_NORMAL;
// hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW;
// HAL_DMA_Init(&hdma_usart1_tx);
//
// __HAL_LINKDMA(&huart1,hdmatx,hdma_usart1_tx);
//
//// HAL_NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0, 0);
//// HAL_NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
//HAL_NVIC_EnableIRQ(USART1_IRQn);
HAL_NVIC_DisableIRQ(USART1_IRQn);
uart_initted = 1;
}
void uart_deinit(void)
{
if(uart_initted == 1)
{
HAL_DMA_DeInit(&hdma_usart1_rx);
HAL_DMA_DeInit(&hdma_usart1_tx);
HAL_UART_DeInit(&huart1);
uart_initted = 0;
}
}
UART_HandleTypeDef* uart_gethandle(void)
{
return &huart1;
}
DMA_HandleTypeDef* uart_get_txdma_handle(void)
{
return &hdma_usart1_tx;
}
DMA_HandleTypeDef* uart_get_rxdma_handle(void)
{
return &hdma_usart1_rx;
}
|