2020-05-19 06:41 PM
Hi!
I am trying to interface the STM32F207's Ethernet peripheral with a KSZ8463 3-port managed switch. I'm using SPI as the management interface, so the MIIM is not connected (MCO + MDIO). So far, I have been able to run the lwIP HTTP server example on the NUCLEO dev board, but have not been able to successfully run the example on our custom PCB, although I am able to read the registers of the switch via SPI and they all seem to be correct (link up, etc), and the switching on ports 1 and 2 works perfectly.
The clock is generated using a 25 MHz oscillator connected to X1 on the KSZ chip, which then generates a 50MHz output on its REFCLK_O pin, which is routed to the RMII_REF_CK pin on the STM32.
Obviously, the standard HAL ETH driver can't communicate with this using its standard PHYReadRegister/PHYWriteRegister commands, but it seems to be getting past the MAC reset, which I understand indicates that the 50MHz reference clock is good.
The code for the lwIP is pretty much the same as the default, except for changing some of the GPIO configuration since the pins are different:
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Alternate = GPIO_AF11_ETH;
GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_4 | GPIO_PIN_5;
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_12 | GPIO_PIN_11 | GPIO_PIN_13;
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
I'm wondering if there is anything that we're missing in terms of connections or configuration, and would be super appreciative since this has caused much confusion.
How the pins are connected on the board is as follows:
STM32 -> Net name -> KSZ8463 pin
PA1 -> RMII_REF_CLK -> 32
PA7 -> RMII_CRS_DV -> 31
PC4 -> RMII_RXD0 -> 35
PC5 -> RMII_RXD1 -> 34
PB11 -> RMII_TX_EN -> 22
PB12 -> RMII_TXD0 -> 26
PB13 -> RMII_TXD1 -> 25
PA5 -> IRQ -> 43
Thank you so much!
2020-05-19 10:42 PM
If it works then you connected everything well. I'm also right now worked with a KSZ switch, tough that it will never work and the problem was RMII_REF_CLK _EN wasn't set to true.
Could you please share the SPI connection & an example reading? Because for me the SPI doesn't want to work, it never replies.
2020-05-20 07:25 AM
Were you able to get Ethernet on the STM to work but not SPI?
Here's our (very preliminary) register reading code:
uint16_t upper9 = 0x7fc; // 0b11111111100
uint16_t readReg(uint16_t reg) {
uint16_t addr = reg & upper9;
uint16_t whichWord = 0;
if (reg & 0x2) {
whichWord = 0xc;
} else {
whichWord = 0x3;
}
uint16_t cmd = (addr << 4) | (whichWord << 2);
uint8_t txreg[4];
uint8_t rxreg[4];
txreg[0] = cmd >> 8;
txreg[1] = cmd & 0xFF;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
HAL_Delay(10);
HAL_SPI_TransmitReceive(&hspi3, txreg, rxreg, 4, 100);
HAL_Delay(10);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
return (rxreg[3] << 8) | rxreg[2];
}
And the SPI configuration:
hspi3.Instance = SPI3;
hspi3.Init.Mode = SPI_MODE_MASTER;
hspi3.Init.Direction = SPI_DIRECTION_2LINES;
hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi3.Init.NSS = SPI_NSS_SOFT;
hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi3.Init.CRCPolynomial = 10;
Currently we're using software slave select until we can get the hardware slave select to do exactly what we need.
2020-05-20 11:05 AM
Thank you!
I misunderstand something before, I modified my first post. From your pin configuration I miss (KSZ pin 23). Look for datasheet "(8463RL, 8463FRL) – RMII Mode:
EN_REFCLKO is used to enable REFCLK_O output on pin 32. If pulled up,
the REFCLK_O output is enabled. If pulled down to disable, the REFCLK_O
output is disabled." https://www.microchip.com/wwwproducts/en/KSZ8463
This was the problem for me why it didn't worked. I had to set this pin to HIGH.
I also tried MCO output from STM32F417 & STM32F107 and on both it didn't worked. Interesting.. We also using crystal too.