MCF52259  FEC  buffer descriptors help

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MCF52259  FEC  buffer descriptors help

Jump to solution
2,688 Views
francois_boucha
Contributor III

Hi all,

I'm struggling to find the bug in my FEC routines.  The bug is that my Rx buffer descriptors (BD) never get updated by the FEC.  They all stay at their initial value. It's like if the FEC does'nt access the right spot in the memory.    Anyways here's some code.  I declare 4 Rx BD as follow:


/* The DMA descriptors.  This is a char array to allow us to align it correctly. */
static uint8 xFECTxDescriptors_unaligned[ ( configNUM_FEC_TX_BUFFERS * sizeof( FECBD ) ) + 16 ];
static uint8 xFECRxDescriptors_unaligned[ ( configNUM_FEC_RX_BUFFERS * sizeof( FECBD ) ) + 16 ];
static FECBD *xFECTxDescriptors;
static FECBD *xFECRxDescriptors;

/* The DMA buffers.  These are char arrays to allow them to be alligned correctly. */
static uint8 ucFECTxBuffers[ ( configNUM_FEC_TX_BUFFERS * configFEC_BUFFER_SIZE ) + 16 ];
static uint8 ucFECRxBuffers[ ( configNUM_FEC_RX_BUFFERS * configFEC_BUFFER_SIZE ) + 16 ];
static uint32 uxNextRxBuffer = 0;
static uint32 uxNextTxBuffer = 0;

The pointers to the BD rings are set here:

 

    /* Point to the start of the circular Rx buffer descriptor queue */
    MCF_FEC_ERDSR = ( volatile uint32 ) &( xFECRxDescriptors[ 0 ] );

    /* Point to the start of the circular Tx buffer descriptor queue */
    MCF_FEC_ETSDR = ( volatile uint32 ) &( xFECTxDescriptors[ 0 ] );

 

My "Rxed Frame" ISR routine is called for each new incoming frames, so I know its getting frames.   

 

My project is based on the MCF52259EVB with CodeWarrior 7.1.1a   (the patch for 52259)

 

Thanks for any suggestions.

FB

Labels (1)
0 Kudos
1 Solution
575 Views
vespaman
Contributor III

Found it! Since I was so focused on the FEC stuff, I missed one very important set-up; letting peripherals write to the internal RAM. (MCF_SCM_RAMBAR) 

 

For everyone in the future stumbling onto this problem.

 

 

View solution in original post

0 Kudos
5 Replies
575 Views
mjbcswitzerland
Specialist V

Hi FB

 

I don't see the control field initialisation values, which are a possible cause of problems.

 

Here is a code for the RX buffer descriptor initialisation from the uTasker project - it is identical for the M5223x and M5225x. Maybe you see something(?)

 

 

 

  EMRBR = pars->usSizeRx;                                                // set receive buffer size
  ptrRxBd = ptrBD = (M5223X_FEC_BD *)uMallocAlign((MAX_MALLOC)(sizeof(M5223X_FEC_BD)*NUMBER_OF_RX_BUFFERS_IN_ETHERNET_DEVICE), 16); // define memory for rx buffer descriptors (aligned on 16 byte boundary)
  ERDSR = (unsigned long)ptrBD;                                          // set pointer to receive descriptor ring
  ptrBuffer = (unsigned char *)uMallocAlign((MAX_MALLOC)(pars->usSizeRx*NUMBER_OF_RX_BUFFERS_IN_ETHERNET_DEVICE), 16);    // get rx buffer memory
  for (i = 0; i < NUMBER_OF_RX_BUFFERS_IN_ETHERNET_DEVICE; i++) {        // initialise each Rx buffer descriptor
      if (i == (NUMBER_OF_RX_BUFFERS_IN_ETHERNET_DEVICE - 1)) {
          ptrBD->usBDControl = (EMPTY_BUFFER | WRAP_BIT);
      }
      else {
          ptrBD->usBDControl = EMPTY_BUFFER;
      }
      ptrBD->ptrBD_Data = ptrBuffer;
      ptrBuffer += pars->usSizeRx;
      ptrBD++;
  }

 

Regards

 

Mark

 

www.uTasker.com

 

- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."

 

0 Kudos
575 Views
francois_boucha
Contributor III

Hi Mark,

 

A couple of FEC routines I got were originally made for the 5282.  Correct me if I'm wrong, but I assume that the 52259 FEC is the same as the 5282's one, so I expect the code to run on both platform. 

 

Anyway,I'm looking at your init code right now.  Here some init code I use on some project:

static void prvInitialiseFECBuffers( void )
{
    uint32 ux;
    uint8 *pcBufPointer;

    pcBufPointer = &( xFECTxDescriptors_unaligned[ 0 ] );
    while( ( ( uint32 ) pcBufPointer & 0x0fUL ) != 0 )
    {
        pcBufPointer++;
    }
  
    xFECTxDescriptors = ( FECBD * ) pcBufPointer;
  
    pcBufPointer = &( xFECRxDescriptors_unaligned[ 0 ] );
    while( ( ( uint32 ) pcBufPointer & 0x0fUL ) != 0 )
    {
        pcBufPointer++;
    }
  
    xFECRxDescriptors = ( FECBD * ) pcBufPointer;


    /* Setup the buffers and descriptors. */
    pcBufPointer = &( ucFECTxBuffers[ 0 ] );
    while( ( ( uint32 ) pcBufPointer & 0x0fUL ) != 0 )
    {
        pcBufPointer++;
    }

    for( ux = 0; ux < configNUM_FEC_TX_BUFFERS; ux++ )
    {
        xFECTxDescriptors[ ux ].status = TX_BD_TC;
        xFECTxDescriptors[ ux ].data = pcBufPointer;
        pcBufPointer += configFEC_BUFFER_SIZE;
        xFECTxDescriptors[ ux ].length = 0;
    }

    pcBufPointer = &( ucFECRxBuffers[ 0 ] );
    while( ( ( uint32 ) pcBufPointer & 0x0fUL ) != 0 )
    {
        pcBufPointer++;
    }
  
    for( ux = 0; ux < configNUM_FEC_RX_BUFFERS; ux++ )
    {
        xFECRxDescriptors[ ux ].status = RX_BD_E;
        xFECRxDescriptors[ ux ].length = configFEC_BUFFER_SIZE;
        xFECRxDescriptors[ ux ].data = pcBufPointer;
        pcBufPointer += configFEC_BUFFER_SIZE;
    }

    /* Set the wrap bit in the last descriptors to form a ring. */
    xFECTxDescriptors[ configNUM_FEC_TX_BUFFERS - 1 ].status |= TX_BD_W;
    xFECRxDescriptors[ configNUM_FEC_RX_BUFFERS - 1 ].status |= RX_BD_W;

    uxNextRxBuffer = 0;
    uxNextTxBuffer = 0;
}

 

 

 

Thanks,

Francois

 

 

0 Kudos
575 Views
vespaman
Contributor III

I am stuck at exactly this problem (rx interrupts, but descriptors left untouched). Also I have done 5280 work before. 

 

While searching the forum, I found your post.. 

 

Did you find any resolution to why this happens?

 

 Thanks,

   Micael 

0 Kudos
576 Views
vespaman
Contributor III

Found it! Since I was so focused on the FEC stuff, I missed one very important set-up; letting peripherals write to the internal RAM. (MCF_SCM_RAMBAR) 

 

For everyone in the future stumbling onto this problem.

 

 

0 Kudos
575 Views
tamirci
Contributor I

Hi Vespaman,

 

Thank you very much to put this not here. I lost 7 days with full of load for this issue and found your answer. It resolved my issue. if you were here i would have taken you to a meal.

 

Best regards,

0 Kudos