Problem with LAN8720

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

Problem with LAN8720

Jump to solution
6,883 Views
arnogir
Senior Contributor II

Hello,

I'm using the K70 150MHz with an Ethernet PHY Lan8720.

I'm using MQX 4.1.1.

I'm using KDS 3.0.0 with a debbuger P&E Multilink Universal.

When I start my software with KDS and P&E debbuger, all Ethernet communication is Ok.

If the board start without debbuger, Ethernet communication not work (I power Off/On with or without JTAG of P&E multilink linked on the board)

I explain :

I have a phy driver which make the following on "Phy_lan8720_init": ( It is same than the provided KSZ8041 driver)

- Get status Register (0x01) and make a infinite loop (With a protection timeout) until status "Auto négociation complete" (bit 5 of status register 1 in my case)

Then after, thank to my code, I'am poll periodically the status to detect link status (Function xxx_get_link_status via IPCFG interface)

1) When I'm using the debbuger (Power is ON since long time...) I have the following:

- In phy_lan8720_init just when enter in the function, display CR and SR:

  a) Control Register 0 value is 0x3100 => Auto-Negotiation Enable : = 1 (Bit 13 and 8 is set to 1 but not usable because bit 12 Auto-Negotiation is 1)

  b) Status register 1 Value is 0x782D : Auto-Negotiate complete, Link status is Up.

Then after, when link status is get, link is Up and all is Ok. If I get status I have 782D, If I get register 31 I get 0x1058...

2) When I'm Power Off/On (Kds is linked OFF, debbuger is kept linked) I have the following:

- In phy_lan8720_init just when enter in function, display CR and SR:

  a) Control Register 0 value is 0x3000 => Auto-Negotiation Enable : = 1 (Bit 13 is set to 1 but not enable because bit 12 Auto-Negotiation is 1, bit 8 is clear..)

  b) Status register 1 Value is 0x7809 : Auto-Negotiate NOT complete, Link status is Down.

Then the loop expire because Auto Negotiate never end before timeout..

Then after, when link status is get, link is down and no connection work. If I get status I have 7809, If I get register 31 I get 0x40!!!!

Whatever Ethernet cable is connected/disconnected, reconnected...To resume, I have exactly this behavior if i'M in the first case (With debbuger) but Ethernet Cable not linked....

Same behavior if debbuger is unplug (Board is alone..)

Maybe the Lan8720 is noise on power ON?

I try on init function to apply a software Reset (CR = 0x8000) and then set CR to 0x3000 or 31000, but this still work with debbuger and not working without him..

Have you some idea????

:smileygrin:

0 Kudos
1 Solution
4,561 Views
arnogir
Senior Contributor II

Hello

In fact The schematic was not correct, the Lled was bad linked so the Power 1.2V was not Ok (this is strange because I had measured it with success...), But I try by hard change and it is Ok now.

Also, the RJ-45 Common was not linked to the TAP 3.3V signal.

View solution in original post

0 Kudos
17 Replies
4,562 Views
arnogir
Senior Contributor II

Hello

In fact The schematic was not correct, the Lled was bad linked so the Power 1.2V was not Ok (this is strange because I had measured it with success...), But I try by hard change and it is Ok now.

Also, the RJ-45 Common was not linked to the TAP 3.3V signal.

0 Kudos
4,561 Views
arnogir
Senior Contributor II

I have not power mode.

Just I try to make a software reset to restart with a good configuration, but he want take the mode auto-negociate...:smileyangry:

I open a discussion on manufacturer here without resolve my problem

http://www.microchip.com/forums/m932740.aspx#933424

Is somebody have a driver which make a software reset to compare to my driver?

0 Kudos
4,561 Views
garrettloverde
Contributor I

Are you playing with the power modes?

My issue was just solved by disabling sleep during the MQX's idle thread. _lpm_idle_sleep(false).

Hypothesis:

Contrary to my original belief that USB Voltage regulator is by default only disabled in STOP and lower modes;

USB voltage regulator is disabled by default in sleep mode and therefore during MQX idle thread as well.

Upon leaving idle thread the regulator doesn't recover fast enough before idling again.

System Mode Controller (SMC) operates differently with debug enabled and was preventing chip from sleeping.

Disconnecting the debugger dirtily left the processor in debug state, hiding the issue until power on reset (battery removal/complete discharge).

0 Kudos
4,561 Views
garrettloverde
Contributor I

I'm having a vaguely similar problem.

After a power on reset and your application is running, have you attempted to connect the debugger to the now "running target"?

I'm using the K70 150Mhz on custom hardware as well.

I'm using MQX 4.2.0 and the old MQX usb library with KHCI to support a USB printer.

Debugging with J-Link. Issue appears regardless of SWD or JTAG

Flash with debugger and run: Printer works

Reset CPU through debugger: Printer works

Disconnect debugger (connector and all) assert pin reset:printer connects, enumerates, etc. still works

Power On reset (POR): printer seems to connect, but the set address setup transaction fails, printer no longer works, otherwise application runs normally.

The next step is really strange to me:

Application is still running after POR, printer still not working.

Connect J-Link to processor via J-Link commander.

Power cycle printer or plug/unplug USB connector and printer works.

0 Kudos
4,560 Views
arnogir
Senior Contributor II

I make this:

int main    (       void    ) { /* Body */ unsigned long i;    extern const MQX_INITIALIZATION_STRUCT MQX_init_struct;

for (i=0;i< 50000 ;i++ ) {   asm("NOP"); }    /* Start MQX */    _mqx( (MQX_INITIALIZATION_STRUCT_PTR) &MQX_init_struct );    return 0;

} /* Endbody */

But the result is the same Smiley Sad

0 Kudos
4,561 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi Arnaud,

I am sorry for making this obvious.Please go to bsp_cm.c which is located in next path:

C:\Freescale\Freescale_MQX_4_2\mqx\source\bsp\<board>

Here you will find __pe_initialize_hardware(void)

Inside this function you will find next comment and there you can place the delay and any other initialization code.

/*** !!! Here you can place your own code before PE initialization using property "User code before PE initialization" on the build options tab. !!! ***/

E.g.

void __pe_initialize_hardware(void)

{

  _bsp_watchdog_disable();

#if MQX_ENABLE_LOW_POWER

    /* Reset from LLWU wake up source */

    if (_lpm_get_reset_source() == MQX_RESET_SOURCE_LLWU)

    {

        PMC_REGSC |= PMC_REGSC_ACKISO_MASK;

    }

#endif

  /*** !!! Here you can place your own code before PE initialization using property "User code before PE initialization" on the build options tab. !!! ***/

_time_delay(2000);

  /*** ### MK70FN1M0VMJ12 "Cpu" init code ... ***/

  /*** PE initialization code after reset ***/

After the changes you must rebuild the BSP library. In this case it is not necessary to rebuild PSP but I always rebuild both no matter what the changes are.


Regards,
Carlos

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
4,561 Views
arnogir
Senior Contributor II

Hello

Thank for your reply.

I try your code exemple with any success. With this, the debugger lost target just after flash it. Then software no start.

May be the function _time_delay() is not yet operational at this stage of init phase?

So I try to replace with

int32_t i;

for (i=0;i< 10000000 ;i++ )

{

  asm("NOP");

}

But without success.

I think if the problem come from explain above, it is not th µC to wait, but LAN8720. Because if I right, the LAN8720 take configuration according its pin when RESET rising Up.

But it is strange this work with bootloader, or for an unknown reason I'm lucky...

I tried to make a LAN8720 software RESET and configure manually to start to make an Auto-config. Without success. May be the change I done was not exactly correct.

Do you know if there are an existing driver somewhere?

Regards,

0 Kudos
4,560 Views
arnogir
Senior Contributor II

Hello

Sorry for many post.

I  investigating on a potential hardware problem that I want  explain you and have your opinion because this could explain something, but not all for me.

On the TOWER-SERIAL, the Ethernet Phy is the KSZ8041NL. Like indicated on the datasheet, the Reset circuit must be specific to hold the RESET longer than the µC because when Reset pin is deasserted, its configuration depends of certain pin placed by the µC. (10/100MBits...)

But on my Sqm4 board, the Phy Etehrnet is LAN8720, but the Configuration from some pin is identical. It is taken when RESET pin goes High.

But on this case, the RESET pin of the LAN8720 and µC are exactly the same. Then the µC pin level should not be conform to the wanted configuration. The good level will appears later.

This could explain why this work with debbuger (By luck, the pin should be on the good state when P&E debbuger assert Reset Pin)

This could explain with bootloader, may be the pin are on the good state also.

And without bootloader with a power ON: The reset is no enough long, so Pin are not Ok.

Unfortunately, I can't check that because the place to modify the SQM4 hardware is too small.

0 Kudos
4,561 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi Arnaud,

all what you say makes sense. The easiest way to workaround this problem would be to make a software delay before configuring the PHY. The delay must be long enough to let the PHY to be ready after the reset. This way you dont need to modify hardware.


Regards,
Carlos

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
4,561 Views
arnogir
Senior Contributor II

I tried to do this, without success.

But I placed a _time_delay(1000) on the Main task (AUTO_STARTED).

I think now is too late to wait the delay.

I must find the startup file or in MQX initialization.. I don't know this part for this moment, I will read..

0 Kudos
4,561 Views
arnogir
Senior Contributor II

I try exemple eth_to_serial_twrk70f120m int Flash DDRData debug on the TOWER-K70 + TOWER-SERIAL.

It work correctly

I try to use file exemple (demo.c and config.h linked on my board with my updated MQX): I have the same bahavior then my application: No connection possible if start with Power ON. So it is not my application responsible, this should come from my adaptation in MQX and/or Driver Phy Ethernet LAN8720 and/or Hardware Phy LAN8720 on Sqm4 Board.

Then I resume my problem here:

Hardware:

I have a K70 150Mhz with a Phy ethernet LAN8720 (Hardware schematic of the SQM4 board is provided above)

I have MQX4.1 where I modified MQX define to work on 150MHz instead of 120MHz.

I have created a Phy driver for MQX (from MQX generic K8041 driver) provided above.

Refer to the provided .doc to see all MQX change....

Problem: In particular case*, the Ethernet connexion is not possible. I have debug this and when problems occurs seen the following behavior on the Phy Driver (My first post): phy_lan8720_init function make an infinite loop (waiting end of auto-negociating). Time Out protection expire.

*This problem occurs only when I flash the program with the P&E debbuger and then Power Off/On the board. Problem not occurs when I Run with debbuger and when it is lunch after an USB bootloader Jump...

Other problem seen: When I flash with debbuger and then make a Reset By pull down the Reset Pin of the JTAG (without POWER Off/On) soft seems not started...This may be a clue to understanding the problem...?

:smileyconfused:

0 Kudos
4,561 Views
arnogir
Senior Contributor II

Hello

I think I will try to reproduce it with following elements:

- Exactly the original USB bootloader find on this forum (I updated it to have some picture on an LCD screen and force to reload USB file when a key is pressed on a keyboard of the board, but modifications seems to me very minor)

- Take the MQX Ethernet exemple.

Then I will see if problem also occurs or not on my board.

1)If problems not occurs, I will check all the differences between my code and the [Ethernet exemple + Original bootloader]

2) If problems occurs, you could try to reproduce on your side with [Ethernet exemple + Original bootloader]. It will be easier for you instead of take my code. (Only the difference between us will be the Ethernet phy if you use the Tower-K70 + Tower-SERIAL, and the clock Frequency because I modified MQX to have CPU clock to 150MHz instead of 120MHz)

I have one think this morning. This is about the Ethernet PHY. On K70 tower eval board (Tower SERIAL), the Ethernet phy is the KZ8041 with the driver provided in MQX. On my board, I'm using a board sqm4-K70 (schematic provided in my previous post), the Ethernet Phy is the LAN8720. Then I create the specific driver for it. May be I have done a mistake in It? I not found on this forum an exemple for this device.

So I provide mine here, may be you could check this driver while I made the test with the MQX exemple + Original  Bootloader.

Thanks

0 Kudos
4,561 Views
arnogir
Senior Contributor II

Hello

I had no back from you.

Have I not been clear enought? Have you need more explain?

Thank you

Regards.

0 Kudos
4,561 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi Arnaud,

I am sorry for the delay.

This case y very strange I am investigating. However the best way I could help is by reproducing this behavior. Do you think there is a way I can replicate this context on my side?

Regards,

Carlos

0 Kudos
4,561 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi Arnaud,

I assume you are using custom hardware, is this correct? My understanding is next:

1) With the debugger you flash and run the application and it works.

    - Are you setting an offset where the application is loaded to avoid overwriting the bootloader?

    - Are you relocating the vector table? How?

2) You load the application using bootloader and it works.

    - In this case bootloader is in address 0x0 and the application is after the bootloader right?

    - Are you relocating the vector table? How?

3) If you make a POR the application does not work.

    - Where is the application loaded?

    - In this case you have the bootlaoder?

    - How do you check if the application should enter in bootloader mode or jump to the app?

    - Does this happen always when you make POR at any time? Or in specific cases?

    - Have you tried POR without the debugger attached?

    - What happen if you reset the application using reset pin?

    - Do you have any of our evaluation borad? The behavior is the same here?

    - After POR the execution is reaching the application entry point?

  

I think problem could be with hardware being affected with POR, timing causing the PHY not to respond correctly or the memory address where you are relocating the application and the vector table. But I need more information. Please let me know the answer to the questions above in order to understand better the context.


Regards,
Carlos

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
4,561 Views
arnogir
Senior Contributor II

Hello

Sorry for the late, but I don't know why, I had not notified by e-mail than an answer was done on my post:smileyconfused:.

I will try to respond on all your point

1) I'm using two different linker file (In KDS i'm using two different Build configuration) according I compile directly in flash with the debbuger or with the Boot.

The difference are on these lines.

With debbuger ( intflash_ddrdara.ld)

    vectorrom   (RX): ORIGIN = 0x00000000, LENGTH = 0x00000400

    cfmprotrom  (R): ORIGIN = 0x00000400, LENGTH = 0x00000020

    rom         (RX): ORIGIN = 0x00000420, LENGTH = 0x000FFBE0  /* Code + Const data */

With Bootloader (intflash_ddrdara_boot.ld):

    vectorrom   (RX): ORIGIN = 0x00020000, LENGTH = 0x00000400

    cfmprotrom  (R): ORIGIN = 0x00020400, LENGTH = 0x00000020

    rom         (RX): ORIGIN = 0x00020420, LENGTH = 0x000DFBE0  /* Code + Const data */

I don't know if I relocate the vector table with my MQX configuration. Are they a specific parameter or a way to know that?

MQX_ROM_VECTORS = 0. Find attached config file

2) i am using the USB host bootloader for the K60 based on the AN4368 adapted to the K70

TWR-K70 MSD HOST Bootloader based on AN4368 source code

I even added a correction described here

Kinetis K70: Bootloader with USB?

The linker of my application shift the code to the 0x2 000 after the  flashed bootlader (See attached linker file intflash_ddrdara_boot.ld)

I relocated the vector table? I think yes but I don't remember the way. I think the bootloader do it correctly.

3)  - Where is the application loaded? - In this case you have the bootloader?

Following are my use cases:

a) compile the application with the linker file  intflash_ddrdara.ld where the code is palced at 0x0, flash it with the debbuger (P&E Multilink universal) With KDS

      - After flash in the KDS "Debug" view, I click on "Run\Resume" -> All work correctly

     - Board is power Off/On (debug session on KDS is out) ->  Problem occurs, Ethernet not work

b) compile the application with the linker file  intflash_ddrdara_boot.ld where the code is palced at 0x2 0000. Flash the K70 USB Host bootlader with teh P&E Multilink. Unplug the JTag, Power Off/On the board, the bootloader wait USB key to flash the application. I insert the USB key with the .S19 of my application. After that, the board is power Off/On.

The Boot start and jump to the application (0x2 0000) -> All work correctly

-How do you check if the application should enter in bootloader mode or jump to the app?

The bootlader send data on a serial port. I can se on an HyperTerminal the state of the bootloader. (Started , Wait USB Key, flashing, jump to the application)

-Does this happen always when you make POR at any time? Or in specific cases?   - Have you tried POR without the debugger attached?

See above (case a) and b)

- What happen if you reset the application using reset pin?

With this question, I complete my test and made the following

A-1) Compile the application with intflash_ddrddata.ld (soft located at 0x0 0000)

A-2) Flash the compiled application with the P&E Multilink universal

A-3) In Kds, on debug view, make RUN/Resume: My application start and the ethernet is operational

A-4) In Kds, on debug view, click on "restart a process...." and then RUN/Resume: My application restart and the ethernet is operational

A-5) Unplug the JTAG link between my board and the P&E Multilink (Nothing append)

A-6) Link Pin 10 and 19 of the JTAG connector (GND and Reset) and remove => My board not start. I haven't way to know if any code begin. It seem NO

A-7) Power Off/On the board: My application start but Ethernet not work

A-8) Link Pin 10 and 19 of the JTAG connector (GND and Reset) and remove =>My application start but Ethernet not work

B-1) Compile the application with intflash_ddrdata_boot.ld (soft located at 0x2 0000)

B-2) Flash the bootloader with the P&E universal multilink  the boot start

B-3)  Unplug the JTAG link between my board and the P&E Multilink (Nothing append)

B-4) Link Pin 10 and 19 of the JTAG connector (GND and Reset) and remove (To test like done on A-6) => Boot restart correcrly (In the same use case, (A-6) my application not start...)

B-5) USB key is plugged and flash begin

B-6) At the end of flash, a jump is done to my application. Application start and Ethernet WORK

B-7) Link Pin 10 and 19 of the JTAG connector (GND and Reset) and remove => My application start and  Ethernet work correctly

B-8) Power Off/On=> My application start and  Ethernet work correctly

B-9) Link Pin 10 and 19 of the JTAG connector (GND and Reset) and remove => My application start and  Ethernet work correctly

- Do you have any of our evaluation borad? The behavior is the same here?

I'm using a specific home board. But the µC with the RAM and flash is the Sqm4 board (Schema provided SQM4_K70_v22_SCH.pdf)

Sorry for the long response but I try to explain the more detail without be ambigus.

Thank for your help:smileyhappy:

0 Kudos
4,561 Views
arnogir
Senior Contributor II

For information, I just test the same code, but not flashed with debbuger, but with the K70 USB bootloader.

So the first code started on the K70 on Power On is the bootloader, which initialize its clock and then jump to the application..

This work!

May be the clock for the Ethernet Phy during the first time after power On is not correct in case of start directly MQX? (because with bootloader, I have a time on start to initialize PLL, with Loop etc...)

??

0 Kudos