-
Notifications
You must be signed in to change notification settings - Fork 223
Ethernet GPIOs not configured correctly #464
Description
This is a follow on from issue #373 .
Bug : Gpio pins for Ethernet are having their speed set to 0x00 ( low speed) instead of high speed, causing the phy interface to fail for high speed operations.
History : we have never been able to get ETH working correctly on the rev1.2 keil board. everything looks right, it just doesn't seem to be able to send and receive messages. We tried a native STMCube base app on the board and it works fine - so not hardware, network etc issues. To try and simplify the problem we laid out some new dev boards. One with an MII phy and one with the RMII (KSZ8081). Both have STMF427 2Mflash and external SDRam. We started off with something more familiar so went back to MF4.3 - We already had ports using the MII phy, and this worked just fine. When we came to the RMII chip, we had the same problem as we have with the keil 1.2 board - works with a 'native' lwip app ( so hardware fine) but not with MF4.3 LWIP - after much debugging I found the problem..
In DeviceCode...\STM32F4_ETH_gpio.cpp each gpio pin required is initialised by a call to CPU_GPIO_DisablePin - passing in pin, altfunction setting etc. The value passed in for the 'alternate' has the gpio speed, and alt function encoded and is a 32bit value ( 0x2b2) - The alternate param is of type GPIO_ALT_MODE - which is an enum with range 0 - 8. The alternate vale of 0xb (ETH), being out of range is not a problem, the compiler is happy with this, but the MDK compiler is optimising the enum storage type, based on the contained values - meaning, it makes it 8 bit - so when we pass in 0x2b2, we get 0xb2. Inside CPU_GPIO_DisablePin, this is fine until we call STM32F4_GPIO_Pin_Config, where all params are correct - except the gpio speed - which now gets passed as 'low' (00) not 'High' (02).
When we use a MII phy, data and clock between processor and phy is 25Mhz or less, and we get away with the 'low' clock' setting. But on the RMII, it is 50Mhz - and we no longer get away with this!
Possibly this is why the Keil STM400 rev 1.1 board works, as the code forces it connect at 10M and half duplex, it seems it does not work at 100M full duplex on MF4.4 - I suspect this is the same problem, when you go down to 10M connection speed - all clocks etc. between processor and phy are 10 times slower than at 100M. I don't think it is a phy problem on this old phy
We have corrected this gpio config problem on our 4.3 port and magically the RMII phy now works.
Temporary work round example can be seen in the MCBSTM32F400 solution - devicecode\Init. If you have a look at the gpio init for external Sram etc. you will see this problem has been seen before!! Answer is
after you call CPU_GPIO_DisablePin() - call STM32F4_GPIO_PinConfig() which will accept the alt function param as an int32 and reconfigure the gpio pin with the correct speed setting.
Not the best, as we effectively call STM32F4..PinConfig twice - but for now it is a simple work round.
I have not had a chance to try this on the MCBSTM32F400 port yet - with a rev 1.2 board - but I am 99% certain it will fix the problem.