This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello,
I was working on a simple program to test the SCI2 and DMA modules and I ran into a couple of problems involving SCI. The code below demonstrates one of the problems. It is intended to read a fixed number of characters from the SCIRD buffer and write them to an array using DMA, where the DMA transfer is HW triggered by SCI whenever data is available to be read. The problem is that the DMA transfer never occurs, even though input characters show up on SCIRD successfully. I think either no transfer request is being sent by SCI, or DMA does not correctly respond to the request. I am using HALCoGen 04.00.00, CCS v5 and the XDS100v2 USB emulator. I am using the CCS terminal to input characters. Here is the sys_main.c file:
/* Include Files */
#include "sys_common.h"
/* USER CODE BEGIN (1) */
#include "sci.h"
#include "sys_dma.h"
/* USER CODE END */
/* USER CODE BEGIN (2) */
g_dmaCTRL ctrl;
unsigned char dest[11] = { 0 };
uint32 btc_flag = 0;
/* USER CODE END */
void main(void)
{
/* USER CODE BEGIN (3) */
_enable_IRQ();
sciInit();
dmaEnable();
/* DMA Channel 0 Control Packet Config (Reading from SCIRD) */
ctrl.SADD = (uint32)((uint8*)&(scilinREG->RD)+3); /* Read the receive buffer byte directly */
ctrl.DADD = (uint32)dest;
ctrl.CHCTRL = 0U; /* Chaining disabled */
ctrl.FRCNT = 11U;
ctrl.ELCNT = 1U;
ctrl.ELDOFFSET = 0U; /* Indexed mode disabled */
ctrl.ELSOFFSET = 0U; /* Indexed mode disabled */
ctrl.FRDOFFSET = 0U; /* Indexed mode disabled */
ctrl.FRSOFFSET = 0U; /* Indexed mode disabled */
ctrl.PORTASGN = 4U; /* Port B */
ctrl.RDSIZE = ACCESS_8_BIT; /* Read a single byte */
ctrl.WRSIZE = ACCESS_8_BIT; /* Write a single byte */
ctrl.TTYPE = FRAME_TRANSFER;
ctrl.ADDMODERD = ADDR_FIXED; /* Fixed address read */
ctrl.ADDMODEWR = ADDR_INC1; /* Post-incremented write */
ctrl.AUTOINIT = AUTOINIT_OFF;
dmaSetCtrlPacket(DMA_CH0, ctrl);
dmaReqAssign(DMA_CH0, 28U);
dmaSetChEnable(DMA_CH0, DMA_HW);
scilinREG->SETINT = (uint32)((uint32)1 << 17); /* Enable SCI DMA request */
/** Transfer start **/
while(btc_flag != 1U); /* Wait until BTC ISR sets the flag */
btc_flag = 0U;
scilinREG->CLEARINT = (uint32)((uint32)1 << 17); /* Disable SCI DMA request */
while(1);
/* USER CODE END */
}
/* USER CODE BEGIN (4) */
void dmaGroupANotification(dmaInterrupt_t inttype, uint32 channel){
btc_flag = 1U;
}
/* USER CODE END */
I can't figure out what I may be doing wrong, because I can successfully write data to SCITD using DMA with the same method and have it printed on the terminal. The following code works without a problem, and prints "Hello world" on the terminal:
/* Include Files */
#include "sys_common.h"
/* USER CODE BEGIN (1) */
#include "sci.h"
#include "sys_dma.h"
/* USER CODE END */
/* USER CODE BEGIN (2) */
g_dmaCTRL ctrl;
unsigned char src[11] = {'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'};
uint32 btc_flag = 0;
/* USER CODE END */
void main(void)
{
/* USER CODE BEGIN (3) */
_enable_IRQ();
sciInit();
dmaEnable();
/* DMA Channel 0 Control Packet Config (Writing to SCITD) */
ctrl.SADD = (uint32)src;
ctrl.DADD = (uint32)((uint8*)&(scilinREG->TD)+3); /* Write on the transmit buffer byte directly */
ctrl.CHCTRL = 0U; /* Chaining disabled */
ctrl.FRCNT = 11U;
ctrl.ELCNT = 1U;
ctrl.ELDOFFSET = 0U; /* Indexed mode disabled */
ctrl.ELSOFFSET = 0U; /* Indexed mode disabled */
ctrl.FRDOFFSET = 0U; /* Indexed mode disabled */
ctrl.FRSOFFSET = 0U; /* Indexed mode disabled */
ctrl.PORTASGN = 4U; /* Port B */
ctrl.RDSIZE = ACCESS_8_BIT; /* Read a single byte */
ctrl.WRSIZE = ACCESS_8_BIT; /* Write a single byte */
ctrl.TTYPE = FRAME_TRANSFER;
ctrl.ADDMODERD = ADDR_INC1; /* Post-incremented read */
ctrl.ADDMODEWR = ADDR_FIXED; /* Fixed address write */
ctrl.AUTOINIT = AUTOINIT_OFF;
dmaSetCtrlPacket(DMA_CH0, ctrl);
dmaReqAssign(DMA_CH0, 29U);
dmaSetChEnable(DMA_CH0, DMA_HW);
scilinREG->SETINT = (uint32)((uint32)1 << 16); /* Enable SCI TX DMA request */
/** Transfer start **/
while(btc_flag != 1U); /* Wait until BTC ISR sets the flag */
btc_flag = 0U;
scilinREG->CLEARINT = (uint32)((uint32)1 << 16); /* Disable SCI TX DMA request */
while(1);
/* USER CODE END */
}
/* USER CODE BEGIN (4) */
void dmaGroupANotification(dmaInterrupt_t inttype, uint32 channel){
btc_flag = 1U;
}
/* USER CODE END */
Attached is the CCS project, in case it is required. Any help would be much appreciated. Thanks a lot in advance.
Cagil
Hello Cagil,
I've forwarded your question to one of our DMA subject matter experts. They will get back with you soon.
Hi Cagil,
I noticed couple of things in the attached project. Fixing these the code was working.
1) Your HALCoGen project was configured for SCI not SCILIN. So sciInit() has only sci not scilin, but your main() DMA configurations are for scilin.
2) You need to Enable RX_DMA_ALL and RX_DMA in SETINT register to handle data if you do not care for multiprocessor communication.
3) You have not Enabled BTC Interrupt in the DMA module, Do like below.
dmaEnableInterrupt(DMA_CH0, BTC);
scilinREG->SETINT = (uint32)((uint32)3 << 17); /* Enable SCI DMA request RM_DMA_ALL + RX_DMA */
Hello Prathap,
Setting the SET RX DMA ALL bit did the trick. I'm sorry about the incorrect HALCoGen setup, I had tried the SCI module after SCI/LIN didn't seem to work, must have forgotten to change back to SCI/LIN.
The program is working perfectly now. Thank you very much.
Cagil
The table in the section "SCI DMA Interface" is very helpful to understand the meaning of these bits.
If there is no such table, you are probably reading about the SCI/LIN module (Section 29 in case of the TMS57012x TRM, depends on family member). There ought to be a copy of or a reference to Table 30-2 in Section 30.4.1).
Hi Chuck,
I stopped doing so after filing dozens of change requests without any feedback. I thought TI is busy with more pressing tasks (answering questions from customers not reading the manual). I do not expect explanations, just a short feedback once in a while to avoid the impression of feeding a null device.
I tried again and found the automatic acknowledgement page changed, now reading "We will be in touch with you very soon."
Best regards
Rainald