My code for W5500 stucks in the socket() function

Hi,
I want to transfer data by connecting the W5500 module to the STM32H7 board. I wanted to test it before starting my project. My test code is as follows. My code gets stuck and does not progress in the socket() function. What could be the problem? I believe I have made the GPIO connections correctly. I used SPI5. What should i do?

/* USER CODE BEGIN Header */

/* USER CODE END Header /
/
Includes ------------------------------------------------------------------*/
#include “main.h”

/* Private includes ----------------------------------------------------------/
/
USER CODE BEGIN Includes */
#include “socket.h”
#include “wizchip_conf.h”
#include <string.h>
#include “loopback/loopback.h”

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------/
/
USER CODE BEGIN PTD /
int sn = 0;
#define mydata “test\n”
int i = 0;
uint8_t bufSizeTx[]={2,2,2,2};
uint8_t bufSizeRx[]={2,2,2,2};
/
USER CODE END PTD */

/* Private define ------------------------------------------------------------/
/
USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------/
/
USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

SPI_HandleTypeDef hspi1;
SPI_HandleTypeDef hspi5;

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);
static void MX_SPI5_Init(void);
/
USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------/
/
USER CODE BEGIN 0 */
void W5500_Select(void) {
HAL_GPIO_WritePin(W5500_CS_EX_GPIO_Port, W5500_CS_EX_Pin, GPIO_PIN_RESET);

}

void W5500_Unselect(void) {
HAL_GPIO_WritePin(W5500_CS_EX_GPIO_Port, W5500_CS_EX_Pin, GPIO_PIN_SET);

}

uint8_t spi_rb(void){
uint8_t cdata;
HAL_SPI_Receive(&hspi5, &cdata, sizeof(cdata), 100);
return cdata;

}

void spi_wb(uint8_t b){
HAL_SPI_Transmit(&hspi5, &b, sizeof(b), 100);

}

enum Status
{
Failed = 0,
Success = 1
};

uint8_t validSetNetInfoResult(wiz_NetInfo* _set, wiz_NetInfo* _get)
{
return(!memcmp(_set, _get, sizeof(wiz_NetInfo)));
}
/* USER CODE END 0 */

/**

  • @brief The application entry point.
  • @retval int
    /
    int main(void)
    {
    /
    USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals /
MX_GPIO_Init();
//MX_SPI1_Init();
MX_SPI5_Init();
/
USER CODE BEGIN 2 */
reg_wizchip_cs_cbfunc(W5500_Select,W5500_Unselect);
reg_wizchip_spi_cbfunc(spi_rb, spi_wb);

wiz_NetInfo gGetNetInfo;
wiz_NetInfo gSetNetInfo = {
.mac = {0x00, 0x08, 0xdc, 0xab, 0xcd, 0xef},
.ip = {192,168,2,192},
.sn = {255, 255,255,0},
.gw = {192,168,2,1},
.dns = {130,130,130,130},
.dhcp = NETINFO_STATIC};

wizchip_setnetinfo(&gSetNetInfo);
HAL_Delay(100);
wizchip_getnetinfo(&gGetNetInfo);
HAL_Delay(100);
wizchip_init(bufSizeTx, bufSizeRx);
HAL_Delay(100);
uint16_t port = 8880;

socket(sn, Sn_MR_TCP, port, SF_TCP_NODELAY);
HAL_Delay(1000);

connect(sn, gSetNetInfo.ip, port);
HAL_Delay(1000);

/* USER CODE END 2 */

/* Infinite loop /
/
USER CODE BEGIN WHILE /
while (1)
{
/
USER CODE END WHILE */

/* USER CODE BEGIN 3 */


i ++;
send(sn, &mydata, strlen(mydata));
if (i == 2){
	break;
}

}

close(sn);
/* USER CODE END 3 */
}

W5500 has 8 sockets.

Before doing anything else try reading the PHYCFGR register to prove you read 0x04.

1 Like

Also i tried by doing
uint8_t bufSizeTx={2,2,2,2,2,2,2,2};
uint8_t bufSizeRx={2,2,2,2,2,2,2,2};

What does it mean by reading PHYCFGR register? Could you expand it?