0
votes

Using STM32CubeMX and Atollic TrueStudio, I created a project with a KSZ8851SNL ethernet controller.

On an STM32H742, I have a driver for the Micrel KSZ8851SNL, and created a micro TCP/IP stack, to test the chip. I got that working very well, but it currentl;y only supports ARP, UDP and ICMP. I can ping in two directions, handle ARP request in both directions, and request NTP time from internet. Now, I would like to let it work together with LwIP. I know it needs to be implemented in a file ethernetif.c. Basically, I used these functions to let the micro setup work:

// Initializes the KSZ8851SNL
uint8_t ksz8851_init(void)

// Send a packet, returns length of received package
// The received length can be checked if we received a packet
uint16_t ksz8851_Receive(uint8_t *pRXData, uint16_t pRXMaxLength)

// Receive a packet
void ksz8851_Send(uint8_t *pTXData, uint16_t pTXLength)

The project is an Atollic TrueStudio project, and I use HAL.

Are above functions sufficient for LwIP? How do I implement this in LwIP? I read lots of documentation, but it seems not detailed to this part.

Sources are on hithub: https://github.com/bkht/STM32H7_HAL_KSZ8851SNL

Thanks a lot for helping me out!

1
The code compiles and runs with no errors, it's just I can't ping the interface. I'm think LwIP doesn't handle the state or the interrupts of the Micrel. I'm sure need to deeper understanding of that part of LwIP, to get it working. I didn't find good examples for the Micrel chip.Jack
Solved: In lwip.c, in the fuction MX_LWIP_Init, I added: if (netif_is_link_up(&gnetif1)) { /* When the netif is fully configured this function must be called / netif_set_up(&gnetif1); } else { / When the netif link is down this function must be called */ netif_set_down(&gnetif1); } I can't get the code shown formatted here. Rgds, Jack.Jack

1 Answers

0
votes

One more thing other than uncomment // MX_LWIP_Init();.

I have an STM32H743 Nucleo-144 and tried to run it(commit number f8ff06c2c17f3d6dacbff8c2fd8eb95591a0c224), too. However, it was stuck in this loop: https://github.com/bkht/STM32H7_HAL_KSZ8851SNL/blob/master/Drivers/KSZ8851SNL/Src/KSZ8851SNL.c#L443-L506 because of a failure of reading chip ID with ksz8851_reg_read() . Then I dig deeper in to the source code, and here is a possible solution:

  1. Change the GPIO setting of SPI2's NSS/CS pin
    GPIO_InitStruct.Pin       = GPIO_PIN_12;
    GPIO_InitStruct.Pull      = GPIO_NOPULL;
    GPIO_InitStruct.Speed     = GPIO_SPEED_FREQ_MEDIUM;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
  1. Uncomment the macro of SPI2 CS Pin https://github.com/bkht/STM32H7_HAL_KSZ8851SNL/blob/master/Drivers/KSZ8851SNL/Inc/KSZ8851SNL.h#L55-L67 and the usage of them(// RESET_SPI_CS_PIN(); & // SET_SPI_CS_PIN();) in https://github.com/bkht/STM32H7_HAL_KSZ8851SNL/blob/master/Drivers/KSZ8851SNL/Src/KSZ8851SNL.c

Then, the correct chip ID will be fetched.

Clement