mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 22:35:23 +03:00
Fix DMA transmit
This commit is contained in:
parent
a70da02c58
commit
bf162b0730
2 changed files with 6 additions and 15 deletions
|
@ -85,8 +85,6 @@ static void uartReconfigure(uartPort_t *uartPort)
|
||||||
if (uartPort->port.mode & MODE_TX)
|
if (uartPort->port.mode & MODE_TX)
|
||||||
uartPort->Handle.Init.Mode |= UART_MODE_TX;
|
uartPort->Handle.Init.Mode |= UART_MODE_TX;
|
||||||
|
|
||||||
SET_BIT(uartPort->USARTx->CR3, USART_CR3_OVRDIS);
|
|
||||||
|
|
||||||
|
|
||||||
usartConfigurePinInversion(uartPort);
|
usartConfigurePinInversion(uartPort);
|
||||||
|
|
||||||
|
@ -131,7 +129,6 @@ static void uartReconfigure(uartPort_t *uartPort)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//__HAL_UART_ENABLE_IT(&s->Handle, UART_IT_RXNE);
|
|
||||||
/* Enable the UART Parity Error Interrupt */
|
/* Enable the UART Parity Error Interrupt */
|
||||||
SET_BIT(uartPort->USARTx->CR1, USART_CR1_PEIE);
|
SET_BIT(uartPort->USARTx->CR1, USART_CR1_PEIE);
|
||||||
|
|
||||||
|
@ -140,7 +137,6 @@ static void uartReconfigure(uartPort_t *uartPort)
|
||||||
|
|
||||||
/* Enable the UART Data Register not empty Interrupt */
|
/* Enable the UART Data Register not empty Interrupt */
|
||||||
SET_BIT(uartPort->USARTx->CR1, USART_CR1_RXNEIE);
|
SET_BIT(uartPort->USARTx->CR1, USART_CR1_RXNEIE);
|
||||||
//HAL_UART_Receive_IT(&s->Handle, (uint8_t*)s->port.rxBuffer, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +168,6 @@ static void uartReconfigure(uartPort_t *uartPort)
|
||||||
/* Associate the initialized DMA handle to the UART handle */
|
/* Associate the initialized DMA handle to the UART handle */
|
||||||
__HAL_LINKDMA(&uartPort->Handle, hdmatx, uartPort->txDMAHandle);
|
__HAL_LINKDMA(&uartPort->Handle, hdmatx, uartPort->txDMAHandle);
|
||||||
|
|
||||||
// __HAL_DMA_ENABLE_IT(s->txDMAHandle, DMA_IT_TC|DMA_IT_FE|DMA_IT_TE|DMA_IT_DME);
|
|
||||||
__HAL_DMA_SET_COUNTER(&uartPort->txDMAHandle, 0);
|
__HAL_DMA_SET_COUNTER(&uartPort->txDMAHandle, 0);
|
||||||
} else {
|
} else {
|
||||||
__HAL_UART_ENABLE_IT(&uartPort->Handle, UART_IT_TXE);
|
__HAL_UART_ENABLE_IT(&uartPort->Handle, UART_IT_TXE);
|
||||||
|
@ -254,7 +249,9 @@ void uartStartTxDMA(uartPort_t *s)
|
||||||
{
|
{
|
||||||
uint16_t size = 0;
|
uint16_t size = 0;
|
||||||
uint32_t fromwhere=0;
|
uint32_t fromwhere=0;
|
||||||
//HAL_UART_DMAStop(&s->Handle);
|
HAL_UART_StateTypeDef state = HAL_UART_GetState(&s->Handle);
|
||||||
|
if((state & HAL_UART_STATE_BUSY_TX) == HAL_UART_STATE_BUSY_TX)
|
||||||
|
return;
|
||||||
|
|
||||||
if (s->port.txBufferHead > s->port.txBufferTail) {
|
if (s->port.txBufferHead > s->port.txBufferTail) {
|
||||||
size = s->port.txBufferHead - s->port.txBufferTail;
|
size = s->port.txBufferHead - s->port.txBufferTail;
|
||||||
|
|
|
@ -309,7 +309,6 @@ void uartIrqHandler(uartPort_t *s)
|
||||||
s->port.rxBuffer[s->port.rxBufferHead] = rbyte;
|
s->port.rxBuffer[s->port.rxBufferHead] = rbyte;
|
||||||
s->port.rxBufferHead = (s->port.rxBufferHead + 1) % s->port.rxBufferSize;
|
s->port.rxBufferHead = (s->port.rxBufferHead + 1) % s->port.rxBufferSize;
|
||||||
}
|
}
|
||||||
//__HAL_UART_CLEAR_IT(huart, UART_IT_RXNE);
|
|
||||||
CLEAR_BIT(huart->Instance->CR1, (USART_CR1_PEIE));
|
CLEAR_BIT(huart->Instance->CR1, (USART_CR1_PEIE));
|
||||||
|
|
||||||
/* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
|
/* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
|
||||||
|
@ -345,19 +344,16 @@ void uartIrqHandler(uartPort_t *s)
|
||||||
/* UART in mode Transmitter ------------------------------------------------*/
|
/* UART in mode Transmitter ------------------------------------------------*/
|
||||||
if((__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET))
|
if((__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET))
|
||||||
{
|
{
|
||||||
//UART_Transmit_IT(huart);
|
HAL_UART_IRQHandler(huart);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* UART in mode Transmitter (transmission end) -----------------------------*/
|
/* UART in mode Transmitter (transmission end) -----------------------------*/
|
||||||
if((__HAL_UART_GET_IT(huart, UART_IT_TC) != RESET))
|
if((__HAL_UART_GET_IT(huart, UART_IT_TC) != RESET))
|
||||||
{
|
{
|
||||||
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_TCF);
|
HAL_UART_IRQHandler(huart);
|
||||||
|
handleUsartTxDma(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if(s->txDMAStream && (s->Handle.TxXferCount == 0) && (s->Handle.TxXferSize != 0))
|
|
||||||
{
|
|
||||||
handleUsartTxDma(s);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleUsartTxDma(uartPort_t *s)
|
static void handleUsartTxDma(uartPort_t *s)
|
||||||
|
@ -367,7 +363,6 @@ static void handleUsartTxDma(uartPort_t *s)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s->txDMAEmpty = true;
|
s->txDMAEmpty = true;
|
||||||
s->Handle.gState = HAL_UART_STATE_READY;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +370,6 @@ void dmaIRQHandler(dmaChannelDescriptor_t* descriptor)
|
||||||
{
|
{
|
||||||
uartPort_t *s = &(((uartDevice_t*)(descriptor->userParam))->port);
|
uartPort_t *s = &(((uartDevice_t*)(descriptor->userParam))->port);
|
||||||
HAL_DMA_IRQHandler(&s->txDMAHandle);
|
HAL_DMA_IRQHandler(&s->txDMAHandle);
|
||||||
handleUsartTxDma(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uartPort_t *serialUART(UARTDevice device, uint32_t baudRate, portMode_t mode, portOptions_t options)
|
uartPort_t *serialUART(UARTDevice device, uint32_t baudRate, portMode_t mode, portOptions_t options)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue