W5500 send is not working

void StartDefaultTask(void *argument)
{
	HAL_UARTEx_ReceiveToIdle_DMA(&huart3, RxBuffer,RxBufferSize);
	  __HAL_DMA_DISABLE_IT(&hdma_usart3_rx,DMA_IT_HT);
		socket(1,Sn_MR_TCP, sending[22],SF_IO_NONBLOCK);
		listen(1);
  for(;;)
  {

			  if((size = getSn_RX_RSR(1)) > 0){    // VERİ GELDİYSE............
			  		recv(1, TxBuffer, size);
			  		aFiltre[1]=0;
			  	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1,GPIO_PIN_SET);
			 HAL_UART_Transmit(&huart3, TxBuffer,size,HAL_MAX_DELAY);
			  	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1,GPIO_PIN_RESET);
			  	size=0;}

  }
  /* USER CODE END StartDefaultTask */
}

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){

send(1,RxBuffer,Size);
HAL_UARTEx_ReceiveToIdle_DMA(&huart3, RxBuffer,RxBufferSize);
}

I can receive the code with recv and transmit the uart files. But after receiving the data from the uart, I cannot send it.
However, when I add a 100ms delay to the Rtos side, the problem is solved. The problem occurs again when I perform a fast data transfer. What should I do? Can you help?

How you can’t send it? I bet send returns status, but you do not read it. You can look at what is going on the network by capturing data exchange at the remote node using e.g. Wireshark.

Where exactly?

It works when I put a delay inside the for loop.

I am having such a problem because I use the send command in the interrupt. I don’t face any problems when I use it in the main loop.
I think the reason is a problem with interrupts. However, when data arrives, it interrupts but exits without sending.
What would be the reason?

Is callback running in separate thread, or in the same thread as for loop? In other words, may there be a W5500 access conflict?

#include "main.h"
#include "dma.h"
#include "spi.h"
#include "usart.h"
#include "usb_device.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "wizchip_conf.h"
#include "string.h"
#include "w5500.h"
#include "loopback.h"
#include "socket.h"
#include "Atama.h"
#include "Eth_Func.h"
#include "Flash.h"
#include "dma.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
#define RxBufferSize 1024
uint8_t RxBuffer[RxBufferSize];
#define TxBufferSize 1024
uint8_t TxBuffer[TxBufferSize];
uint16_t size=0;
uint8_t a=0;
/* ------------------------------------------------------------------------MAİN DOSYASINDAN DEN ÇA�?IRANLAR DE�?İ�?KENLER-----------------------------------------------------------------*/
extern DMA_HandleTypeDef hdma_usart3_rx;


uint16_t size1 = 0;
/* 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 ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){
	HAL_UARTEx_ReceiveToIdle_IT(&huart3, RxBuffer,RxBufferSize);
	send(1,RxBuffer,Size);

}
/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
	uint8_t bufSize[]={2, 2, 2, 2};
  /* USER CODE END 1 */

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

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

  /* USER CODE BEGIN Init */
	HAL_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_DMA_Init();
  MX_SPI1_Init();
  MX_USART3_UART_Init();
  MX_USB_DEVICE_Init();
  /* USER CODE BEGIN 2 */
  /* ------------------------------------------------------------------------RS485 DE-RE BACAK PİNİ--------------------------------------------------------------------------*/
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1,GPIO_PIN_RESET);
  /* ------------------------------------------------------------------------W5500 AKTİVE KODLARI--------------------------------------------------------------------------*/
  reg_wizchip_cs_cbfunc(cs_sel, cs_desel);
  reg_wizchip_spi_cbfunc(spi_rb, spi_wb);
  wizchip_init(bufSize, bufSize);
  wiz_NetInfo netInfo = { .mac 	= {0xDA,0x01, 0xFE,0x00, 0x45,0xAA},	// Mac address
                                     .ip 	= {192,168,1,68},					// IP address
                                     .sn 	= {192,168,1,1,},					// Subnet mask
                                     .gw 	= {255,255,255,0},
             						.dns ={8,8,8,8},
									.dhcp =NETINFO_STATIC
  	  	  	  	  	  	  	  	  	};		// Gateway address
  wizchip_setnetinfo(&netInfo);
  wizchip_getnetinfo(&netInfo);
/* ------------------------------------------------------------------------Gelen Veri ve giden veri boyut size ayarı--------------------------------------------------------------------------*/
  setSn_RXBUF_SIZE(1,8);
  setSn_TXBUF_SIZE(1,8);
    HAL_UARTEx_ReceiveToIdle_IT(&huart3, RxBuffer,RxBufferSize);
  	 		socket(1,Sn_MR_TCP,500,SF_TCP_NODELAY);
  	 		listen(1);
//------------------------------------------------------------------------- FREERTOS BA�?LIYOR-------------------------------------------------------------------------
  /* USER CODE END 2 */

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

    /* USER CODE BEGIN 3 */
		if(getSn_SR(1)==SOCK_ESTABLISHED){
		 					  if((size = getSn_RX_RSR(1)) > 0){    // VERİ GELDİYSE............
		 					  		recv(1, TxBuffer, size);
		 					  	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1,GPIO_PIN_SET);
		 					 HAL_UART_Transmit_DMA(&huart3, TxBuffer,size);

		 					  	size=0;}}
		HAL_Delay(1);

  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSI
                              |RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 1;
  RCC_OscInitStruct.PLL.PLLN = 8;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart){
  	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1,GPIO_PIN_RESET);
}

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
	HAL_NVIC_SystemReset();
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

All code as above.

Please help me.

How can I help - you must provide info I asked for. Status code for send, and if callback runs in threaded mode.

What exactly the command for delay?

I am struggling with the problem to solve it. And finally I discovered this. If I constantly query getSn_RX_RSR(sn) as polling, I have problems with send(). I observed an improvement when I increased the duration of the getSn_Rx_RSR(sn) query.
What can i do in this situation.

My best regards,

IMHO you anyway seem to be doing something wrongly, and you’ll sometimes get the faults.
If execution is threaded, then there may be access concurrency to the chip. Even if you do not use threading and using interrupts, if interrupt occurs during executing chip access you’ll get faulty result.

Actually the situation is this. I constantly perform the send operation on the interrupt when there is a getSn_RX_RSR query. It works fine when I put a wait or remove the getSn_RX_RSR query. I’m using the W5500 chip’s own libraries.
I’m trying hard to solve this problem I’m encountering.
I’m open to your ideas.

When accessing chip with single command or in specific sequence in main loop you must disable interrupts.

Bu soruna ait bir çözüm www.bekdemir.com.tr sitesinde mevcuttur.
Fazlası ile yardımcı oldu, özellikle stud çivisi ile alakalı olarak