Hi Alice,
i just have setup a little example:
#include "pin_mux.h"
#include "board.h"
#include "fsl_usart.h"
#include "fsl_usart_dma.h"
#include "fsl_dma.h"
#include "fsl_debug_console.h"
#include "fsl_usart_dma.h"
#include <stdbool.h>
#include "fsl_power.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define USART_TX_DMA_CHANNEL 5
/*******************************************************************************
* Variables
******************************************************************************/
usart_dma_handle_t g_uartDmaHandle;
usart_handle_t g_usart_handle;
dma_handle_t g_uartTxDmaHandle;
uint8_t g_tipString[] = "USART DMA example\r\nWrite this text and\r\nEcho every character immediatly\r\n";
uint8_t g_rxBuffer = 0;
volatile bool txOnGoing = false;
usart_config_t config;
usart_transfer_t xfer;
/*******************************************************************************
* Code
******************************************************************************/
void FLEXCOMM0_IRQHandler(void)
{
uint8_t data;
uint32_t flags = USART_GetStatusFlags(USART0);
/* If new data arrived. */
if ((kUSART_RxFifoNotEmptyFlag | kUSART_RxError) & flags)
{
g_tipString[0]=USART_ReadByte(USART0);
DMA_EnableChannel(DMA0, USART_TX_DMA_CHANNEL);
USART_TransferCreateHandleDMA(USART0, &g_uartDmaHandle, NULL, NULL, &g_uartTxDmaHandle, NULL);
/* Send g_tipString out. */
xfer.data = g_tipString;
xfer.dataSize = 1;
txOnGoing = true;
USART_TransferSendDMA(USART0, &g_uartDmaHandle, &xfer);
}
if((kUSART_TxFifoEmptyFlag | kUSART_TxError) & flags)
{
USART0->INTENCLR = USART_INTENCLR_TXIDLECLR_MASK;
if(txOnGoing)
txOnGoing = false;
}
SDK_ISR_EXIT_BARRIER;
}
int main(void)
{
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
USART_GetDefaultConfig(&config);
config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
config.enableTx = true;
config.enableRx = true;
USART_Init(USART0, &config, CLOCK_GetFlexCommClkFreq(0U));
/* Configure DMA. */
DMA_Init(DMA0);
DMA_EnableChannel(DMA0, USART_TX_DMA_CHANNEL);
DMA_CreateHandle(&g_uartTxDmaHandle, DMA0, USART_TX_DMA_CHANNEL);
USART_TransferCreateHandleDMA(USART0, &g_uartDmaHandle, NULL, NULL, &g_uartTxDmaHandle, NULL);
/* Send g_tipString out. */
xfer.data = g_tipString;
xfer.dataSize = sizeof(g_tipString) - 1;
txOnGoing = true;
USART_TransferSendDMA(USART0, &g_uartDmaHandle, &xfer);
/* Wait send finished */
while (txOnGoing)
{
}
USART_TransferCreateHandle(USART0, &g_usart_handle, NULL, NULL);
USART_EnableInterrupts(USART0, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable);
EnableIRQ(FLEXCOMM0_IRQn);
while (1)
{
__NOP();
}
}
How can i suppress to get into the FLEXCOMM0_IRQHandler() after finishing transmit?
Why i need to call USART_TransferCreateHandleDMA(USART0, &g_uartDmaHandle, NULL, NULL, &g_uartTxDmaHandle, NULL); every time, although I have already created the handles globally and called the function already in the main routine?
Also, I left out the DMA_Callback function for TX in the example, since it is not called anyway. Since the FLEXCOMM0_IRQHandler() is always called before. If I don't clear the TXIDLE flag in the FLEXCOMM0_IRQHandler(), I don't get out of the FLEXCOMM0_IRQHandler() at all.
if((kUSART_TxFifoEmptyFlag | kUSART_TxError) & flags)
{
USART0->INTENCLR = USART_INTENCLR_TXIDLECLR_MASK;
if(txOnGoing)
txOnGoing = false;
}If the TXIDLE flag is cleared, the DMA_Callback function for TX is not called anymore. Is there anything that can be done about this?
BR
Ralf