cancel
Showing results for 
Search instead for 
Did you mean: 

Ethernet/LWIP Problems on the STM32H755ZIQ nucleo-board

kyleg4032
Associate II

Hello,

I am currently attempting to get the ethernet set up on my eval board. The project goal is to use a timer on the eval board to trigger the board to call out to a PLC on my network to receive 8 values every 1 second. Those values will then be stored in specific corresponding variables in the main.c file to be used in another function later on. I have attempted to follow several examples and use some AI to help me debug but I have hit a wall. I have zero errors when building out the project and running the debugger. It appears to flash onto the device but then nothing happens.

List of the places that I have tried to debug with a simple toggle GPIO command on one of the user LEDs

-user code section 2 : did toggle successfully on

-main while loop : does not work

-user code section 4 with in my modbus request : does not work

I have had several cases where it appears when the debugger asks me to resume the process it sends me to the hard fault handler in stm32H7xx_it.c, but this leaves me even more confused as to where to begin my debug process as I am so new to this. I at one point could ping the STM32 on my network but now I unfortunately get destination host unreachable. However, all of the hardware lights on the ethernet port do work!

 

The following are the components in the hardware config that I have activated and their settings:

System Core: GPIO / set USER LEDs to GPIO output on the M7 core only, no other changes

Timers: TIM2 activated on M7 / Counter period to 240000000 / TRGO set to Reset / NVIC TIM2 global interrupt checked

Connectivity: ETH activated on M7 only / NVIC global interrupt checked

Connectivity: USART3 Activated for Asynchronous mode

Middleware: FREERTOS_M7 on / API set to CMSIS v1 / USE_NEWLIB_REENTRANT Enabled / Default Task Enabled

Middleware: LWIP Enabled for M7 / DHCP disabled and static IP set / Platform settings to LAN8742

 

The following is the code I have implemented in my main.c ----------------------

 
#include "cmsis_os.h"

#include "lwip.h"

/* USER CODE BEGIN Includes */

#include "lwip/api.h"

#include "lwip/netbuf.h"

#include "lwip/ip_addr.h"

#include "lwip/tcp.h"

#include <string.h>

#include <stdio.h>



/* USER CODE END Includes */

/* USER CODE BEGIN PV */

/* Ethernet Packet Buffer */

uint8_t modbus_tx_buffer[12]; // Modbus Request Frame

uint8_t modbus_rx_buffer[1024];



/* Variables to store received Modbus values */

float phase_set_point, amplitude_set_point;

float phase_p, phase_i, phase_d;

float amp_p, amp_i, amp_d;



/* UART Debug Buffer */

uint8_t uart_msg[100];

extern UART_HandleTypeDef huart3;

/* USER CODE END PV */

/* USER CODE BEGIN 2 */

/* Initialize LWIP and Ethernet */

MX_LWIP_Init();



/* Start TIM2 for Modbus updates */

MX_TIM2_Init();

HAL_TIM_Base_Start_IT(&htim2);

/* USER CODE END 2 */

/* USER CODE BEGIN 4 */

void modbus_send_request(void)

{

struct netconn *conn;

struct netbuf *buf;

ip_addr_t server_ip;



IP4_ADDR(&server_ip, 000, 000, 000, 000);

conn = netconn_new(NETCONN_TCP);



if (conn != NULL)

{

if (netconn_connect(conn, &server_ip, 502) == ERR_OK)

{

modbus_tx_buffer[0] = 0x00;

modbus_tx_buffer[1] = 0x01;

modbus_tx_buffer[2] = 0x00;

modbus_tx_buffer[3] = 0x00;

modbus_tx_buffer[4] = 0x00;

modbus_tx_buffer[5] = 0x06;

modbus_tx_buffer[6] = 0x01;

modbus_tx_buffer[7] = 0x03;

modbus_tx_buffer[8] = 0xD4;

modbus_tx_buffer[9] = 0xDC;

modbus_tx_buffer[10] = 0x00;

modbus_tx_buffer[11] = 0x10;



netconn_write(conn, modbus_tx_buffer, 12, NETCONN_NOCOPY);



if (netconn_recv(conn, &buf) == ERR_OK && buf != NULL)

{

memcpy(modbus_rx_buffer, buf->p->payload, buf->p->len);

netbuf_delete(buf);



phase_set_point = (modbus_rx_buffer[9] << ‌‌ | modbus_rx_buffer[10];

amplitude_set_point = (modbus_rx_buffer[11] << ‌‌ | modbus_rx_buffer[12];

phase_p = (modbus_rx_buffer[13] << ‌‌ | modbus_rx_buffer[14];

phase_i = (modbus_rx_buffer[15] << ‌‌ | modbus_rx_buffer[16];

phase_d = (modbus_rx_buffer[17] << ‌‌ | modbus_rx_buffer[18];

amp_p = (modbus_rx_buffer[19] << ‌‌ | modbus_rx_buffer[20];

amp_i = (modbus_rx_buffer[21] << ‌‌ | modbus_rx_buffer[22];

amp_d = (modbus_rx_buffer[23] << ‌‌ | modbus_rx_buffer[24];



sprintf((char*)uart_msg, "Modbus Data: PSet=%.2f, ASet=%.2f\n", phase_set_point, amplitude_set_point);

HAL_UART_Transmit(&huart3, uart_msg, strlen((char*)uart_msg), HAL_MAX_DELAY);

}



netconn_close(conn);

netconn_delete(conn);

}

}

}



void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

{

if (htim->Instance == TIM2)

{

modbus_send_request();

HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_14);

}

}

/* USER CODE END 4 */

I have left the IP address blank on purpose

I will also say that I have tried to click through every line and over things in the main.c file, it appeared that it was breaking after osKernelStart but I am unsure at this time.

/* Create the thread(s) */

/* definition and creation of defaultTask */

osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);

defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);



/* USER CODE BEGIN RTOS_THREADS */

/* add threads, ... */

/* USER CODE END RTOS_THREADS */



/* Start scheduler */

osKernelStart();



/* We should never get here as control is now taken by the scheduler */

 

Any help or ideas of where to go from here would be greatly appreciated or tutorials that you might know of, thank you!

 

12 REPLIES 12
STackPointer64
ST Employee

Hello once again @kyleg4032,

Have you managed to resolve your problem? If so, please click Accept as Solution on the reply that helped you. This will assist other users who may have the same issue in the future.

Best regards,

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.

Hi @STackPointer64 ,

I apologize for the late reply, I so far have not come up with a way to resolve my problem and due to time constraints on what I am doing, I have decided to forgo the use of Ethernet in my project at this time. I have had the USB communication running for quite some time and created a python code that will work in tandem with the microcontroller so it will receive the values it requires to function over that USB communication.

 

In the future though, I might return to try and get the Ethernet capabilities up and running but not for this initial design I am working on.

 

Thank you again though for taking the time to reply and provide resources to help me, I truly appreciate it!

 

-Kyle

Hello,

Thank you for your update @kyleg4032. You’re very welcome! It’s great to hear you’ve made progress with the USB communication and Python integration. Prioritizing your project timeline is important, and returning to Ethernet later sounds like a solid plan. If you need any help in the future, don’t hesitate to ask.

Best regards,

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.