Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "board.hpp"
- #include "pin_mux.h"
- #include "clock_config.h"
- #include "fsl_dmamux.h"
- #include "fsl_edma.h"
- #include "fsl_uart.h"
- #include "fsl_uart_edma.h"
- #include "fsl_pit.h"
- static uint8_t buff[513];
- static volatile uint32_t dma_complete_count = 0;
- static volatile uint32_t transfer_done_count = 0;
- static void dma_irq(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds)
- {
- dma_complete_count++;
- if (transferDone)
- {
- transfer_done_count++;
- }
- }
- int main(void)
- {
- BOARD_InitBootPins();
- BOARD_BootClockRUN();
- BOARD_InitDebugConsole();
- // ==================================================================================
- // UART config
- // ==================================================================================
- uart_config_t uartConfig;
- UART_GetDefaultConfig(&uartConfig);
- uartConfig.baudRate_Bps = 250000;
- uartConfig.enableRx = false;
- uartConfig.enableTx = false;
- if(kStatus_Success != UART_Init(UART1, &uartConfig, CLOCK_GetFreq(UART1_CLK_SRC)))
- {
- MSG("Failed to init UART1\n");
- }
- // Disable FIFO buffer (enabled by default)
- UART1->PFIFO &= ~(UART_PFIFO_TXFE_MASK | UART_PFIFO_RXFE_MASK);
- UART_EnableTx(UART1, true);
- // ==================================================================================
- // PIT config
- // ==================================================================================
- pit_config_t config;
- PIT_GetDefaultConfig(&config);
- PIT_Init(base, &config);
- // disable interrupts for our channel
- PIT_DisableInterrupts(PIT, kPIT_Chnl_2, kPIT_TimerInterruptEnable);
- // stops the channel if it's already running
- PIT_StopTimer(PIT, kPIT_Chnl_2);
- // clear the interrupt flag
- PIT_ClearStatusFlags(PIT, kPIT_Chnl_2, kPIT_TimerFlag);
- // ==================================================================================
- // DMA config
- // ==================================================================================
- // configure our DMA
- DMAMUX_Init(DMAMUX);
- edma_config_t edma_config;
- EDMA_GetDefaultConfig(&edma_config);
- EDMA_Init(DMA0, &edma_config);
- edma_handle_t edmaHandleTx;
- DMAMUX_DisableChannel(DMAMUX, 2);
- DMAMUX_SetSource(DMAMUX, 2, kDmaRequestMux0UART1Tx);
- DMAMUX_EnableChannel(DMAMUX, 2);
- EDMA_CreateHandle(&edmaHandleTx, DMA0, 2);
- EDMA_SetCallback(&edmaHandleTx, dma_irq, NULL);
- // ==================================================================================
- // Do Send
- // ==================================================================================
- for (int i = 0; i < 10; i++)
- {
- buff[i] = i;
- }
- edma_transfer_config_t xferConfig;
- EDMA_PrepareTransfer(&xferConfig, buff, sizeof(uint8_t),
- (void *)UART_GetDataRegisterAddress(UART1),
- sizeof(uint8_t), sizeof(uint8_t), 10, kEDMA_MemoryToPeripheral);
- EDMA_SubmitTransfer(&edmaHandleTx, &xferConfig);
- EDMA_StartTransfer(&edmaHandleTx);
- // Setup the timer for data send rate
- PIT_SetTimerPeriod(PIT, kPIT_Chnl_2, 10800); // 300us (bus clock 36MHz)
- PIT_StartTimer(PIT, kPIT_Chnl_2);
- // Use PIT to trigger DMA
- DMAMUX_EnablePeriodTrigger(DMAMUX, 2);
- // Enable UART TX EDMA
- // DMA will start sending data once the running timer elapses
- UART_EnableTxDMA(UART1, true);
- while(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement