Infinite loop with mac_lld_start() and STM3220G-EVAL

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
TexZK
Posts: 57
Joined: Sat Sep 22, 2012 7:06 pm

Infinite loop with mac_lld_start() and STM3220G-EVAL

Post by TexZK »

Hi! I am trying to port the STM3220G-EVAL board to ChibiOS 2.5.0, in order to use the Ethernet bus. The problem is that mac_lld_start() loops forever at the following while loop:

Code: Select all

  /* MAC clocks activation and commanded reset procedure.*/
  rccEnableETH(FALSE);
  ETH->DMABMR |= ETH_DMABMR_SR;
  while(ETH->DMABMR & ETH_DMABMR_SR)
    ;

The phyter works in MII mode, clocked at 25MHz. It is possible to find its address (=1, correct) with mii_find_phy(), so it can communicate successfully. It looks like to be a problem related to the STM32F207, since that software reset has actually nothing to do with the external phyter itself, but only with the Ethernet DMA.
The ST demos work correctly, so it is not an hard fault, but some wrong initialization procedure which I'm not able to fix by myself.
I've checked all the pins configuration, the MCO1 or dedicated crystal outputs, and everything seems ok. The only HAL peripherals enabled are TM, PAL, MAC, and SERIAL.

Have you any idea about what is wrong in my configuration, or even in the (unstable?) MAC driver?
Thanks in advance :)
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Infinite loop with mac_lld_start() and STM3220G-EVAL

Post by Giovanni »

Hi,

The driver is tested on the F4 and we already found that the F2 header file is filled of errors, probably the difference is there. Another possible source of problems is the correct initialization in boards/ST_STM3220G_EVAL/board.h, the Ethernet pins are not initialized in that (contributed) file, did you add the correct initialization?

Giovanni
User avatar
TexZK
Posts: 57
Joined: Sat Sep 22, 2012 7:06 pm

Re: Infinite loop with mac_lld_start() and STM3220G-EVAL

Post by TexZK »

Yes, I almost rewrote the entire board.h. Only the Ethernet and JTAG related pins were assigned an alternate function, plus some spare LEDs. A LWIP demo and the board configuration can be found as attachments, based on the Olimex E407 demo.

Actually, I'm willing to make a custom F4 board, but at the moment I only have this F2 one available, which could contribute to ChibiOS if working.
Attachments
ARMCM3-STM32F207-STM3220G-LWIP.zip
LWIP demo (NOT working!)
(135.64 KiB) Downloaded 639 times
STM3220G-EVAL_board_cfg.zip
STM3220G-EVAL board configuration (Ethernet only)
(6.09 KiB) Downloaded 643 times
User avatar
TexZK
Posts: 57
Joined: Sat Sep 22, 2012 7:06 pm

Re: Infinite loop with mac_lld_start() and STM3220G-EVAL

Post by TexZK »

Sorry, if you mean the STM32F2xx platform files (especially the stm32f2xx.h header) then no, I haven't touched them.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Infinite loop with mac_lld_start() and STM3220G-EVAL

Post by Giovanni »

TexZK wrote:Sorry, if you mean the STM32F2xx platform files (especially the stm32f2xx.h header) then no, I haven't touched them.


That file has a lot of bugs, could you try to replace it with the F4 one? just rename it. F2 and F4 are almost identical except for minor details.

Giovanni
User avatar
TexZK
Posts: 57
Joined: Sat Sep 22, 2012 7:06 pm

Re: Infinite loop with mac_lld_start() and STM3220G-EVAL

Post by TexZK »

Unfortunately, exactly the same happens with the F4 header (and its contents) renamed... :(
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Infinite loop with mac_lld_start() and STM3220G-EVAL

Post by Giovanni »

It must be something with the board files then.

I suggest you create the board.h and board.c files not manually but using the automatic generator present in ChibiStudio.

Start from the OLIMEX_STM32_E407 board, under the "cfg" subdirectory there is a configuration (board.chcfg) file, open it in ChibiStudio and configure your board (note that you can edit the file in text mode or graphic mode, make sure to use the graphic mode because it is guided), the generator tool can create the files automatically by clicking its button in the toolbar while the .chcfg file is selected.

The use of the tool excludes a lot of possible errors.

Giovanni
User avatar
TexZK
Posts: 57
Joined: Sat Sep 22, 2012 7:06 pm

Re: Infinite loop with mac_lld_start() and STM3220G-EVAL

Post by TexZK »

Ok, luckily I've been borrowed an F4-based prototype which works with ChibiOS and LWIP. I've checked every project file but the board.h, and nothing was significantly different from the ones provided with ChibiOS 2.5.0.
So, it's really possible that my board.h is wrong somewhere, as you supposed :geek: I still have to compare mine and theirs to see what is wrong, and if I spot the subtle error I will let you know ;)
iggarpe
Posts: 129
Joined: Sun Sep 30, 2012 8:32 pm

Re: Infinite loop with mac_lld_start() and STM3220G-EVAL

Post by iggarpe »

I had a similar problem, so here's my two cents, might help:

while(ETH->DMABMR & ETH_DMABMR_SR)
;

The above code will loop forever if the MAC doesn't have an active external 25MHz clock. Make sure it's clocked.

Just for the record, in my case I'm using a LAN8720A in RMII mode. Besides being tiny, the LAN8720A is nice because it will generate the 50MHz RMII clock from a cheap 25MHz crystal (otherwise you'd need a relatively expensive 50MHz oscillator). Problem is that the mac_lld driver puts the PHY in powerdown mode and in that state the LAN8720A 50MHz clock is disabled, so the STM32 MAC is not clocked and the code will loop forever waiting for the SR bit to clear in DMABMR.

I fixed it with some though out reordering of the initialization in the mac_lld driver. See bug and patch here:

https://sourceforge.net/tracker/?func=d ... tid=995489

Maybe your 25MHz come from a clock output of your PHY and it's disabled in powerdown mode?
Post Reply