Well, you have changed the default structure of the CODE BEGIN/END blocks, which CubeMX cannot handle. In its raw state, the while loop looks like this:
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
You have turned it into:
/* USER CODE BEGIN WHILE */
while (1)
{
ethernetif_input(&gnetif);
sys_check_timeouts();
}
/* USER CODE END 3 */
...so the end marker of the block WHILE and the start marker of the block 3 are deleted. How should CubeMX then sort its own code?
There are deliberately two areas in the WHILE loop so that you can insert your own code at the beginning or at the end, so that you can build it up as shown below. Among other things, CubeMX keeps the option open to place automatically generated code in the WHILE later, which would not be feasible if the entire WHILE were user code:
/* USER CODE BEGIN WHILE */
while (1)
{
// user code at the beginning of the while loop
HAL_GPIO_WritePin(GPIO_Port, Pin, GPIO_PIN_SET); // dummy code for illustration
HAL_Delay(20); // dummy code for illustration
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
// user code at the end of the while loop
HAL_GPIO_WritePin(GPIO_Port, Pin, GPIO_PIN_RESET); // dummy code for illustration
HAL_Delay(20); // dummy code for illustration
}
/* USER CODE END 3 */
I would therefore recommend inserting your code only in the first block, i.e. directly before USER CODE END WHILE.
Regards
/Peter