Ivan Bolgarov

MCF52235 - FEC buffer ring

Discussion created by Ivan Bolgarov on Sep 4, 2007
Latest reply on Sep 7, 2007 by Paul McConkey
I have problem with FEC driver creation. I use mcf52235. I've discovered that problem in FEC driver's buffers. I've simplified driver and now it's just initialization function. Here is definitions:
// defines
#define FEC_BUF_SIZE 256              // buffer size
#define N_TX_BUF 16                        // number of buffers
#define N_RX_BUF 16
// variables
#pragma pack(1)
typedef struct {
 volatile unsigned short status;
 volatile unsigned short length;
 volatile char *buffer;
#pragma pack()
char desc[sizeof(FEC_BUF_DESC)*(N_RX_BUF+N_TX_BUF)+15];
char txBuffer[N_TX_BUF*FEC_BUF_SIZE+15];
char rxBuffer[N_RX_BUF*FEC_BUF_SIZE+15];
char *pch;                              // tmp
// code
 pRXBD = (FEC_BUF_DESC *)(((long)desc+15)&0xFFFFFFF0);              // pointer to BD-rx-ring
 pTXBD = pRXBD + N_RX_BUF;                                                                  // pointer to BD-tx-ring
 MCF_FEC_ERDSR = (unsigned long)pRXBD;
 MCF_FEC_ETDSR = (unsigned long)pTXBD;
 pch = (char *)(((long)rxBuffer+15)&0xFFFFFFF0);                                     // rx data buffer
 for ( i = 0; i < N_RX_BUF; ++i ) {
  pRXBD[i].status = MCF_FEC_RxBD_E;
  pRXBD[i].buffer = pch+i*FEC_BUF_SIZE;
 pRXBD[N_RX_BUF-1].status |= MCF_FEC_RxBD_W;                             // tx data buffer
 pch = (char *)(((long)txBuffer+15)&0xFFFFFFF0);
 for ( i = 0; i < N_TX_BUF; ++i ) {
  pTXBD[i].status = 0;
  pTXBD[i].buffer = pch+i*FEC_BUF_SIZE;
 pTXBD[N_TX_BUF-1].status |= MCF_FEC_TxBD_W;
This is map-file:
  20002370 0000100F .bss    txBuffer (fec.c)
  20003380 0000100F .bss    rxBuffer (fec.c)
  20004390 0000010F .bss    desc (fec.c)
Somehow happens that FEC fills rxBuffer and damages desc also. After that data memory corrupts and my program makes many miracles. I'm sure that problem in memory corruption, I've spent halfweek for searching. Here are several notes:
1. If I exchange memory locations of rxBuffer and txBuffer program works fine. I've simplified program and it doesn't use txBuffer. Array desc isn't corrupted.
2. If I initialize all pointers and registers but don't enable FEC (ETHER_EN) program works fine. FEC doesn't fork but it hasn't miracles.
3. If I remove simplification FEC driver works fine during short time. Just before miracles starts.
4. if I set FEC_BUF_SIZE equal 1520 (1 frame/buffer) program works fine. No miracles at all.
I just cannot find problems in my buffer's configuration. Help me please.

Alban Edit: Please always include FSL Part Number in Message Subject line.


Message Edited by Alban on 2007-09-07 03:07 PM