We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

Showing results for 
Search instead for 
Did you mean: 
Observer skyfall133
Registered: ‎05-08-2018

[Artix 7] How to config DMA to transmit more than one BD in Scatter Gather mode

Hi there, 

   I am learning to use DMA in Scatter Gather mode to test with loopback. I use example code (xaxidma_example_sg_poll.c), and test it successfully. But in that code, they just transmit one packet (use 1 BD ). 

   With Rx channel: 


//Dont need to config anything for control 
//The hardware will set the SOF/EOF bits per stream status XAxiDma_BdSetCtrl(BdCurPtr, 0);

   Wtih Tx channel: 



/* For single packet, both SOF and EOF are to be set*/

     As the code above, with Tx channel, it uses for transmitting singer packet (use 1 BD).  I want to transmit more 1 packet, it means use more than 1 BD. So i edit SendData function in example code: 



static int SendPacket(XAxiDma * AxiDmaInstPtr)
	XAxiDma_BdRing *TxRingPtr;
	u8 *TxPacket;
	u8 Value;
	XAxiDma_Bd *BdPtr;
	XAxiDma_Bd *BdCurPtr;
	int Status;
	int Index;

	TxRingPtr = XAxiDma_GetTxRing(AxiDmaInstPtr);

	/* Create pattern in the packet to transmit */
	TxPacket = (u8 *) Packet;


	for(Index = 0; Index < 2*MAX_PKT_LEN; Index ++) {
		TxPacket[Index] = Value;
		xil_printf ("TX addr: %x  and value: %x\n\r", (unsigned int)(TxPacket+Index),(unsigned int)*(TxPacket+Index));
		Value = (Value + 1) & 0xFF;
	/* Allocate 2 BDs */
	Status = XAxiDma_BdRingAlloc(TxRingPtr, 2, &BdPtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	BdCurPtr = BdPtr;
	for (Index = 0; Index < 2;Index ++){
	/* Set up the BD using the information of the packet to transmit */
	Status = XAxiDma_BdSetBufAddr(BdCurPtr, (UINTPTR) Packet);
	if (Status != XST_SUCCESS) {
		xil_printf("Tx set buffer addr %x on BD %x failed %d\r\n",
		    (UINTPTR)Packet, (UINTPTR)BdCurPtr, Status);

		return XST_FAILURE;
	Status = XAxiDma_BdSetLength(BdCurPtr, MAX_PKT_LEN,
	if (Status != XST_SUCCESS) {
		xil_printf("Tx set length %d on BD %x failed %d\r\n",
		    MAX_PKT_LEN, (UINTPTR)BdCurPtr, Status);

		return XST_FAILURE;
	xil_printf ("TX BD addr: %x  and value: %x\n\r", BdCurPtr,TxPacket);

	/* For 2 packet, both SOF and EOF are to be set*/
if (Index == 0) XAxiDma_BdSetCtrl(BdCurPtr,XAXIDMA_BD_CTRL_TXSOF_MASK); if (Index == 1) XAxiDma_BdSetCtrl(BdCurPtr,XAXIDMA_BD_CTRL_TXEOF_MASK); XAxiDma_BdSetId(BdCurPtr, (UINTPTR)Packet); TxPacket += MAX_PKT_LEN; BdCurPtr = (XAxiDma_Bd *)XAxiDma_BdRingNext(TxRingPtr, BdCurPtr); } /* Give the BD to DMA to kick off the transmission. */ Status = XAxiDma_BdRingToHw(TxRingPtr, 2, BdPtr); if (Status != XST_SUCCESS) { xil_printf("to hw failed %d\r\n", Status); return XST_FAILURE; } return XST_SUCCESS; }

  But it doesn't run well. Status = XST_FAILURE, it means "XAxiDma_Bdring()" not right. That is error i meet. 



Any suggestion for me ? And how to use more than BDs in Tx Channel ? 
P.S: Example code is attached.

Tags (1)
0 Kudos
2 Replies
Observer skyfall133
Registered: ‎05-08-2018

Re: [Artix 7] How to config DMA to transmit more than one BD in Scatter Gather mode

Can anyone help me ? 

0 Kudos
Xilinx Employee
Xilinx Employee
Registered: ‎10-04-2016

Re: [Artix 7] How to config DMA to transmit more than one BD in Scatter Gather mode

Hi @skyfall133,

To debug this, I would start by looking at the contents of the two BDs in memory. Are they formatted as you expect?

I'd also turn on debug messages in the driver to see where it is failing in the XAxiDma_BdRingToHw function. There are a number of failing conditions and it would help to know which one you are hitting.



Don’t forget to reply, kudo, and accept as solution.
0 Kudos