Page 1 of 1
Infinite loop with mac_lld_start() and STM3220G-EVAL
Posted: Thu Oct 04, 2012 11:43 am
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

Re: Infinite loop with mac_lld_start() and STM3220G-EVAL
Posted: Thu Oct 04, 2012 12:48 pm
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
Re: Infinite loop with mac_lld_start() and STM3220G-EVAL
Posted: Thu Oct 04, 2012 2:55 pm
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.
Re: Infinite loop with mac_lld_start() and STM3220G-EVAL
Posted: Thu Oct 04, 2012 3:34 pm
by TexZK
Sorry, if you mean the STM32F2xx platform files (especially the stm32f2xx.h header) then no, I haven't touched them.
Re: Infinite loop with mac_lld_start() and STM3220G-EVAL
Posted: Thu Oct 04, 2012 3:37 pm
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
Re: Infinite loop with mac_lld_start() and STM3220G-EVAL
Posted: Fri Oct 05, 2012 9:25 am
by TexZK
Unfortunately, exactly the same happens with the F4 header (and its contents) renamed...

Re: Infinite loop with mac_lld_start() and STM3220G-EVAL
Posted: Fri Oct 05, 2012 9:49 am
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
Re: Infinite loop with mac_lld_start() and STM3220G-EVAL
Posted: Mon Oct 15, 2012 3:32 pm
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

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

Re: Infinite loop with mac_lld_start() and STM3220G-EVAL
Posted: Thu Oct 18, 2012 8:37 pm
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=995489Maybe your 25MHz come from a clock output of your PHY and it's disabled in powerdown mode?