Wrestling with MAC on F107 Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Wrestling with MAC on F107

Post by avrhack »

I've been wrestling since yesterday trying to get a working MAC/LWIP baseline project working under GCC and it's doing my head in. There don't seem to be any relevant examples that I can find - none of the F107 ones are MAC; this is only for the F407.

There's clearly something wrong with my combination of board/Makefile/chconf/mcuconf but the current nightmare is "error: 'ETH_MACMIIAR_CR_Div42' undeclared" when trying to compile mac_lld.c

I can see this is defined in the CMSIS f107 header, I can see that should be included by the f1xx CMSIS, I can see that be included by the cmparams.h which is in turn pulled in by chcore.h however clearly something is not working here.

My board.h defines STM32F107xC and the includes in my makefile are:

Code: Select all

# Startup files.
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_stm32f1xx.mk
# HAL-OSAL files (optional).
include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/hal/ports/STM32/STM32F1xx/platform_f105_f107.mk
include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# Other files (optional).
include $(CHIBIOS)/os/various/lwip_bindings/lwip.mk


Any pointers please and/or examples of a working F107 MAC project?
avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Re: Wrestling with MAC on F107

Post by avrhack »

OK now this is VERY strange. The issue is case - the defines seem to be wrong in mac_lld.c, but looking at a git blame they were last changed by Giovani on 4th August 2013 so I can't see how this can possibly be it. However changing to the correct case solves the build problem for me - or rather this one at least.....

Offending lines from mac_lld.c are:

Code: Select all

/* MII divider optimal value.*/
40   #if (STM32_HCLK >= 150000000)
41   #define MACMIIDR_CR ETH_MACMIIAR_CR_Div102
42   #elif (STM32_HCLK >= 100000000)
43   #define MACMIIDR_CR ETH_MACMIIAR_CR_Div62
44   #elif (STM32_HCLK >= 60000000)
45   #define MACMIIDR_CR     ETH_MACMIIAR_CR_Div42
46   #elif (STM32_HCLK >= 35000000)
47   #define MACMIIDR_CR     ETH_MACMIIAR_CR_Div26
48   #elif (STM32_HCLK >= 20000000)
49   #define MACMIIDR_CR     ETH_MACMIIAR_CR_Div16
50   #else
51   #error "STM32_HCLK below minimum frequency for ETH operations (20MHz)"
52   #endif


This is a direct lift from the current view on github ie not my local drive to rule out any local issues and you can clearly see that the definitions are wrong compared to CMSIS.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Wrestling with MAC on F107

Post by Giovanni »

Hi,

It is possible that latest ST headers changed those ETH_ declarations.

Moving into the bug reports forum, to be checked.

Giovanni
zeroping
Posts: 4
Joined: Wed Jul 29, 2015 3:48 pm
Been thanked: 1 time

Re: Wrestling with MAC on F107

Post by zeroping »

I actually hit this a little while ago, and failed to mention the fix.

In ChibiOS-RT/os/ext/CMSIS/ST/STM32F1xx/stm32f107xc.h , I copied in the definitions from the 207, and they worked just fine for me. It appears that the capitalization is slightly different (CR_DIV42 vs CR_Div42). The result looks like this:

Code: Select all

/* Bit definition for Ethernet MAC MII Address Register */
#define ETH_MACMIIAR_PA         ((uint32_t)0x0000F800)  /* Physical layer address */
#define ETH_MACMIIAR_MR         ((uint32_t)0x000007C0)  /* MII register in the selected PHY */
#define ETH_MACMIIAR_CR         ((uint32_t)0x0000001C)  /* CR clock range: 6 cases */
  #define ETH_MACMIIAR_CR_Div42   ((uint32_t)0x00000000)  /* HCLK:60-100 MHz; MDC clock= HCLK/42 */
  #define ETH_MACMIIAR_CR_Div16   ((uint32_t)0x00000008)  /* HCLK:20-35 MHz; MDC clock= HCLK/16 */
  #define ETH_MACMIIAR_CR_Div26   ((uint32_t)0x0000000C)  /* HCLK:35-60 MHz; MDC clock= HCLK/42 */
#define ETH_MACMIIAR_MW         ((uint32_t)0x00000002)  /* MII write */
#define ETH_MACMIIAR_MB         ((uint32_t)0x00000001)  /* MII busy */


Giovanni, would you like a real patch? Or is this good enough?

Also, avrhack, I have LWIP working wonderfully on my STM32F107 board with a KSZ8091 PHY. I can try to provide additional help. Ethernet on the STM32F107 is the road less traveled, so you may hit another issue. I'm not sure if we should continue in this thread or what, but PM me if you'd like.
avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Re: Wrestling with MAC on F107

Post by avrhack »

Just to confirm that I now have the F107 working with a KSZ8863RMII as the PHY although testing so far is limited to getting a DHCP address and responding to IGMP pings however if that's working through LWIP then clearly all of the MAC/PHY stuff is operational.

The 8863 is very useful as it's actually a 3-port switch with 100BaseT PHYS on 2 of the ports and an RMII PHY interface on the 3rd port which I've connected to the F107. This allows the F107 to effectively be inserted into any Ethernet 10/100 drop cable relatively seamlessly. At the moment mine is connected using MDC/MDIO which allows a limited view/configuration of the 8863's pair of PHYs but not the switch parameters, however the benefit is that it works without modification of Giovani's low-level driver as it looks like a standard MII.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Wrestling with MAC on F107

Post by Giovanni »

hi,

I am going through all pending tickets, if you have fixes or patches please post them here.

Giovanni
avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Re: Wrestling with MAC on F107

Post by avrhack »

Giovanni wrote:I am going through all pending tickets, if you have fixes or patches please post them here.
Giovanni


I think it would be very useful to allow a user to override mii_read and mii_write without having to change ChibiOS' source code. As an example, when I'm using the KSZ8863 only one of the two upstream ports is monitored by the MAC LLD code; if I could easily provide my own mii_read and mii_write they could simulate a single MII using the data from both upstream switch ports. Similarly if I wanted to interface the PHY using i2c I could re-write the mii_read and mii_write routines to use i2c instead of the MAC SMI.

At the moment there is an element of support for this using BOARD_PHY_RESET but it doesn't provide the full flexibility.

Other than that, the CMSIS case issues already in this thread and the bug 772 that you've already said is fixed, I haven't had to change anything to get this working with the KSZ8863 even though it's not really a single PHY.

Thanks.
avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Re: Wrestling with MAC on F107

Post by avrhack »

Giovanni wrote:hi,

I am going through all pending tickets, if you have fixes or patches please post them here.

Giovanni


I noticed this is marked as resolved - my fault - but the defect of the case issues with CMSIS in mac_lld.c are not in the current fix list from what I can see so wanted to make sure this is still on your radar for the next release Giovanni?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Wrestling with MAC on F107

Post by Giovanni »

Removed the mark.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Wrestling with MAC on F107

Post by Giovanni »

Bumped.
Post Reply