Hello everyone,
I do a basic code to understand how uDMA work but it got me into a problem, i use ping-pong mode to receive data from UART0 RX and after each interrupt it handle data receive and reset uDMA uart even the Tranfer size of buffer B not done yet . So after first successfull receive, it seem the uDMA and UART stop working, i sent another frame to tiva and use debug break point but no thing happend, it not jump in to interrupt part. Can you help me fix it pls?. Thanks
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_udma.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_uart.h"
#include "inc/hw_ints.h"
#include "inc/hw_gpio.h"
#include "inc/hw_types.h"
#include "inc/tm4c123gh6pm.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/uart.h"
#include "driverlib/interrupt.h"
#include "driverlib/udma.h"
#include "driverlib/timer.h"
#if defined(ewarm)
#pragma data_alignment=1024
uint8_t DMAcontroltable[1024];
#elif defined(ccs)
#pragma DATA_ALIGN(DMAcontroltable, 1024)
uint8_t DMAcontroltable[1024];
#else
uint8_t DMAcontroltable[1024] __attribute__ ((aligned(1024)));
#endif
uint8_t BufferA[100];
uint8_t BufferB[100],myArray[102];
uint8_t CRC[2],receivedone ;
uint32_t ReceiveLength, a, count = 0, count_uDMA_A =0,count_uDMA_B =0;
//=======================================reset UART uDMA=========================================//
void uDMAConfig(){
/* tDMAControlTable *psControlTable;
uint32_t ui32Control;
HWREG(UDMA_CTLBASE) = (uint32_t)DMAcontroltable;
psControlTable = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
ui32Control = (psControlTable[UDMA_CH8_UART0RX].ui32Control)&~UDMA_CHCTL_XFERMODE_M;
ui32Control |=UDMA_MODE_STOP;
psControlTable[UDMA_CH8_UART0RX].ui32Control |= ui32Control;
*/
uDMAChannelDisable(UDMA_CH8_UART0RX);
uDMAChannelControlSet(UDMA_CH8_UART0RX | UDMA_PRI_SELECT,
UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 |
UDMA_ARB_1);
uDMAChannelControlSet(UDMA_CH8_UART0RX | UDMA_ALT_SELECT,
UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 |
UDMA_ARB_1);
uDMAChannelTransferSet(UDMA_CH8_UART0RX | UDMA_PRI_SELECT,
UDMA_MODE_PINGPONG,
(void *)(UART0_BASE + UART_O_DR), BufferA,
2);
uDMAChannelTransferSet(UDMA_CH8_UART0RX | UDMA_ALT_SELECT,
UDMA_MODE_PINGPONG,
(void *)(UART0_BASE + UART_O_DR), BufferB,
100);
uDMAChannelEnable(UDMA_CH8_UART0RX);
}
//===================================handle receive data =================================//
void CheckRequest(void)
{
int i = 0;
myArray[0] = BufferA[0];
myArray[1] = BufferA[1];
for(i = 0;i<100;i++)
{
myArray[2+i]=BufferB[i];
}
for(i = 0; i<100;i++){BufferB[i]=0;}
BufferA[0]=0;BufferA[1]=0;
if(myArray[0]==1)
{
CRC_calculation(myArray,ReceiveLength);
if(CRC[1]==0 & CRC[0]==0)
{
FunctionCheck();
}
}
}
void FunctionCheck()
{
switch(myArray[1])
{
case 2:
a = 2;
UARTCharPut(UART0_BASE, a);
break;
case 4:
a = 4;
UARTCharPut(UART0_BASE, a);
break;
case 15:
a = 15;
UARTCharPut(UART0_BASE, a);
break;
case 16:
a = 16;
UARTCharPut(UART0_BASE, a);
//====================interrupt after buffA full ========================///
void UARTInterrupt(){
uint32_t ui32Status,ui32Mode;
ui32Status = UARTIntStatus(UART0_BASE, true); //get interrupt status
UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts
//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1); //blink LED
//SysCtlDelay(SysCtlClockGet() / (1000 * 3)); //delay ~1 msec
//GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0); //turn off LED
ui32Mode = uDMAChannelModeGet(UDMA_CH8_UART0RX | UDMA_PRI_SELECT);
count++;
if(ui32Mode == UDMA_MODE_STOP){
count_uDMA_A++;
/*uDMAChannelTransferSet(UDMA_CH8_UART0RX | UDMA_PRI_SELECT,
UDMA_MODE_PINGPONG,
(void *)(UART0_BASE + UART_O_DR), BufferA,
2);*/
SysCtlDelay(20); // wait for ALT buffB
if(BufferA[0] == 1){
if(BufferA[1] == 4 || BufferA[1] == 2)
{
ReceiveLength=8;
receivedone = 1;
}
if(BufferA[1]==16 || BufferA[1] == 15)
{
receivedone = 1;ReceiveLength=BufferB[6]+9;
}
}
}
//================================main ====================================================//
void main(void) {
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
UARTFIFODisable(UART0_BASE);
//UARTFIFOEnable(UART0_BASE);
//UARTFIFOLevelSet(UART0_BASE,UART_FIFO_TX4_8,UART_FIFO_RX4_8);
SysCtlPeripheralClockGating(true);
//UARTIntRegister(UART0_BASE,&UARTInterrupt);
IntMasterEnable();
IntEnable(INT_UART0);
//UARTIntEnable(UART0_BASE, UART_INT_RX );
UARTDMAEnable(UART0_BASE, UART_DMA_RX );
SysCtlPeripheralDisable(SYSCTL_PERIPH_UDMA);
SysCtlPeripheralReset(SYSCTL_PERIPH_UDMA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
SysCtlDelay(10);
uDMAEnable();
uDMAControlBaseSet(DMAcontroltable);
uDMAChannelAssign(UDMA_CH8_UART0RX);
uDMAChannelAttributeDisable(UDMA_CH8_UART0RX,
UDMA_ATTR_ALTSELECT | UDMA_ATTR_USEBURST |
UDMA_ATTR_HIGH_PRIORITY |
UDMA_ATTR_REQMASK);
uDMAChannelControlSet(UDMA_CH8_UART0RX | UDMA_PRI_SELECT,
UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 |
UDMA_ARB_1);
uDMAChannelControlSet(UDMA_CHANNEL_UART0RX | UDMA_ALT_SELECT,
UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 |
UDMA_ARB_1);
uDMAChannelTransferSet(UDMA_CH8_UART0RX | UDMA_PRI_SELECT,
UDMA_MODE_PINGPONG,
(void *)(UART0_BASE + UART_O_DR), BufferA,
2);
uDMAChannelTransferSet(UDMA_CH8_UART0RX | UDMA_ALT_SELECT,
UDMA_MODE_PINGPONG,
(void *)(UART0_BASE + UART_O_DR), BufferB,
100);
uDMAChannelEnable(UDMA_CH8_UART0RX);
UARTCharPut(UART0_BASE, 'E');
UARTCharPut(UART0_BASE, 'n');
UARTCharPut(UART0_BASE, 't');
UARTCharPut(UART0_BASE, 'e');
UARTCharPut(UART0_BASE, 'r');
UARTCharPut(UART0_BASE, ' ');
UARTCharPut(UART0_BASE, 'T');
UARTCharPut(UART0_BASE, 'e');
UARTCharPut(UART0_BASE, 'x');
UARTCharPut(UART0_BASE, 't');
UARTCharPut(UART0_BASE, ':');
UARTCharPut(UART0_BASE, ' ');
while (1)
{
if(receivedone == 1)
{
CheckRequest();
uDMAConfig();
receivedone = 0;
}