Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Problem with AT91SAM7X256 and KS8721 Ethernet PHY MAC
PostPosted: Wed Feb 07, 2007 9:19 pm 
Offline

Joined: Sat Dec 16, 2006 12:26 am
Posts: 3
Location: Poland
Hello everyone.

I am programming my own device based on AT91SAM7X256. It is equiped with ethernet controller - KS8721 by Micrel.

My problem is I can't to read any of the registers in the PHY. MAC chip don't respond to any of my readings. I've checked on oscilloscope does AT91 sends any signals to PHY, and it does. The frame is correct, but after the first frame (request to read) clock on MDC line is clocking, but data from PHY don't appear.
Doed anybody use the same MAC controller?


Thanks for help!

Bart.

Source code:

// ====================================================================

unsigned int Eth_ReadPHY(unsigned char PHYAddress, unsigned char PHYReg)
{
unsigned int val;

val = EMAC_SOF |
EMAC_PHY_RD |
EMAC_PHY_CODE |
(PHYAddress & 0x1f) << 23 |
(PHYReg & 0x1f) << 18;

DebugPrint("Eth_ReadPHY -> Zapisuję %08x do EMAC_MAN \n", val);
AT91C_BASE_EMAC->EMAC_MAN = val;
while( !(AT91C_BASE_EMAC->EMAC_NSR & AT91C_EMAC_IDLE)) {}
val = AT91C_BASE_EMAC->EMAC_MAN;
DebugPrint("Eth_ReadPHY -> Odczytałem %08x z EMAC_MAN \n", val);
return ( val & 0x0000ffff );
}

void Eth_WritePHY(unsigned char PHYAddress, unsigned char PHYReg, unsigned int data)
{
unsigned int val;

val = EMAC_SOF |
EMAC_PHY_WR |
EMAC_PHY_CODE |
(PHYAddress & 0x1f) << 23 |
(PHYReg & 0x1f) << 16 |
data;

DebugPrint("Eth_WritePHY -> Zapisuję %08x do EMAC_MAN \n", val);
while( !(AT91C_BASE_EMAC->EMAC_NSR & AT91C_EMAC_IDLE)) {}
DebugPrint("Eth_ReadPHY -> Zezwolenie na zapis jest.\n", val);
AT91C_BASE_EMAC->EMAC_MAN = val;
while( !(AT91C_BASE_EMAC->EMAC_NSR & AT91C_EMAC_IDLE)) {}
DebugPrint("Eth_WritePHY -> Zapisano wartość \n");
}

// ====================================================================

void Init_PHY(void)
{
unsigned int val;

DebugPrint("\nKonfiguracja PHY\n");

// Odczytanie wartości z rejestru PHY

DebugPrint("Czytam PHY spod adresu MII_BMCR... \n");
val = Eth_ReadPHY(EMAC_PHY_ADDR, MII_BMCR);
DebugPrint("OK. \n");
DebugPrint("MII_BMCR = %04x \n", val);

// Zmiana - konfiguracja PHY
val |= BMCR_FULLDPLX | BMCR_SPEED100;
DebugPrint("Zmieniam wartość z MII_BMCR na %04x \n", val);
Eth_WritePHY(EMAC_PHY_ADDR, MII_BMCR, val);

// Odczekanie
DebugPrint("\nCzekam ... \n");
Wait(1);
DebugPrint("OK. \n");

// Odczytanie rejestru - sprawdzenie czy zmiany się dokonały
DebugPrint("Czytam PHY spod adresu MII_BMCR... \n");
val = Eth_ReadPHY(EMAC_PHY_ADDR, MII_BMCR);
DebugPrint("OK. \n");
DebugPrint("MII_BMCR = %04x \n", val);
}


// ====================================================================

void Init_Ethernet(void)
{
// Konfiguracja IO Ethernetu

DebugPrint("\nKonfiguracja Ethernetu\n");

// Konfiguracja PIO
// Reset i Power Down - disable it

AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, EMAC_PWRDWN);
AT91F_PIO_SetOutput( AT91C_BASE_PIOA, EMAC_PWRDWN);

AT91F_PIO_CfgOutput( AT91C_BASE_PIOB, EMAC_RESET);
AT91F_PIO_SetOutput( AT91C_BASE_PIOB, EMAC_RESET);

AT91F_PIO_CfgPeriph(
AT91C_BASE_PIOB,
0,
emacPERIPHERAL_SETUP);

AT91C_BASE_PIOB->PIO_PPUER |= AT91C_PB9_EMDIO;

// Wlaczenie zegara dla Ethernetu
AT91F_EMAC_CfgPMC();

// Włączenie Ethernetu
AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, EMAC_ONOFF);

if (eth_on)
AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, EMAC_ONOFF);
else
AT91F_PIO_SetOutput( AT91C_BASE_PIOA, EMAC_ONOFF);

DebugPrint("\nCzekam ... \n");
Wait(5);
DebugPrint("OK. \n");

DebugPrint("Reset ... \n");
AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, EMAC_RESET);
Wait(10);
DebugPrint("OK ... \n");
AT91F_PIO_SetOutput( AT91C_BASE_PIOB, EMAC_RESET);

// Wypisanie zawartości rejsestrów EMAC

DebugPrint("Aktualna konfiguracja: \n");
DebugPrint("EMAC_NCR = %08x \n", AT91C_BASE_EMAC->EMAC_NCR);
DebugPrint("EMAC_NCFGR = %08x \n", AT91C_BASE_EMAC->EMAC_NCFGR);
DebugPrint("EMAC_NSR = %08x \n", AT91C_BASE_EMAC->EMAC_NSR);

// Zmiana - konfiguracja EMAC

DebugPrint("Zmiana konfiguracji: Włączenie komuniacji z PHY .\n");
AT91C_BASE_EMAC->EMAC_NCR = AT91C_EMAC_MPE;
DebugPrint("EMAC_NCR = %08x \n", AT91C_BASE_EMAC->EMAC_NCR);
AT91C_BASE_EMAC->EMAC_NCFGR = AT91C_EMAC_CLK_HCLK_16;
DebugPrint("EMAC_NCFGR = %08x \n", AT91C_BASE_EMAC->EMAC_NCFGR);

// Odczekanie 1 sekundy po konfiguracji MDC i MDIO

DebugPrint("\nCzekam ... \n");
Wait(5);
DebugPrint("OK. \n");

Init_PHY();
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 9:39 pm 
Offline

Joined: Sat Dec 16, 2006 12:26 am
Posts: 3
Location: Poland
Hi.

It's me again.

I'm adding output of terminal messages (sorry for Polish language, but it doesn't metter - c langage is the main language ;-)):

==================
Konfiguracja Ethernetu

Czekam ...
OK.
Reset ...
OK ...
Aktualna konfiguracja:
EMAC_NCR = 00000000
EMAC_NCFGR = 00000800
EMAC_NSR = 00000006
Zmiana konfiguracji: Włączenie komuniacji z PHY .
EMAC_NCR = 00000010
EMAC_NCFGR = 00000400

Czekam ...
OK.

Konfiguracja PHY
Czytam PHY spod adresu MII_BMCR...
Eth_ReadPHY -> Zapisuję 60020000 do EMAC_MAN
Eth_ReadPHY -> Odczytałem 6003ffff z EMAC_MAN
OK.
MII_BMCR = ffff
Zmieniam wartość z MII_BMCR na ffff
Eth_WritePHY -> Zapisuję 5002ffff do EMAC_MAN
Eth_ReadPHY -> Zezwolenie na zapis jest.
Eth_WritePHY -> Zapisano wartość

Czekam ...
OK.
Czytam PHY spod adresu MII_BMCR...
Eth_ReadPHY -> Zapisuję 60020000 do EMAC_MAN
Eth_ReadPHY -> Odczytałem 6003ffff z EMAC_MAN
OK.
MII_BMCR = ffff

=====================

Bye, and thanks for any replies.
Bart.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 9:18 am 
Offline

Joined: Sat Dec 16, 2006 12:26 am
Posts: 3
Location: Poland
Hi.

Good news. I solved the problem.

The only reason why my PHY doesn't wanted to reply on my readings was bad configuration of PIOs on SAM7X. Because of pull-ups enabled by default on SAM, strapping options for PHY was not well configured. Every pin line on PHY that belongs to strapping options pin group can't have pull-up connected at powerup or reset of PHY. That's why before I've turned on PHY i disabled pull-ups on every PIO pin connected to PHY (KS8721) - except MDIO line which require pull-up.

So, bye and good luck.
Apacz (Bart).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 02, 2007 6:10 pm 
Offline

Joined: Thu Feb 22, 2007 5:40 pm
Posts: 26
Location: Italy
You may be my master.
I need to develop a firmware for my company that is going to use them (µC + KS8721).
In general we use IP, UDP and HDLC inside.

Do you use RTOS for EMAC porpuse?
Do you have any training to give me?
What can you do for a NOt skilled guy?

:roll:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: