STM32H563ZI (NUCLEO-H563ZI) and NETXDUO DHCP CLIENT
Hello
I am developing on the NUCLEO-H563ZI board a system in which I need to obtain an IP address via DHCP.
I have implemented the client following the guidelines of the documentation provided by ST as well as THREADX and NETXDUO and, I have strange behavior.
The system rarely completes all message transaction between the NUCLEO board and the DHCP server on my system. It usually stays alltime in a loop sending a DISCOVER and ignoring the server's OFFER response.

From time to time, it succeds to perform the full message cycle DISCOVER-OFFER-REQUEST-ACK, but then remains in a loop continuously performing a REQUEST and ignoring the ACK.

I think I have a runtime or thread priority problem. I've tried everything and I can't get out of this dynamic.
The hardware works with other codes (not using DHCP).
I'm stalled here.
This is the code that I'm using:
NX_PACKET_POOL dhcp_client_pool;
NX_IP client_ip;
NX_DHCP dhcp_client;
TX_THREAD dhcp_client_thread;
CHAR *pointer;
UCHAR message[50] = "Hello from DHCP Client";
ULONG dhcp_client_thread_counter;
ULONG dhcp_client_state_changes;
ULONG dhcp_client_error_counter;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
void dhcp_client_thread_entry(ULONG thread_input);
void dhcp_state_change_CB(NX_DHCP *dhcp_ptr,UCHAR new_state);
/* USER CODE END PFP */
/**
* @brief Application NetXDuo Initialization.
* @PAram memory_ptr: memory pointer
* @retval int
*/
UINT MX_NetXDuo_Init(VOID *memory_ptr) {
UINT status = NX_SUCCESS;
TX_BYTE_POOL *byte_pool = (TX_BYTE_POOL*)memory_ptr;
/* USER CODE BEGIN App_NetXDuo_MEM_POOL */
(void)byte_pool;
/* USER CODE END App_NetXDuo_MEM_POOL */
/* USER CODE BEGIN 0 */
pointer = (CHAR *)(byte_pool->tx_byte_pool_start);
tx_thread_create(&dhcp_client_thread, "DHCP Client Thread", dhcp_client_thread_entry, 0,
pointer, DEMO_STACK_SIZE,
2, 2, TX_NO_TIME_SLICE, TX_AUTO_START);
pointer = pointer + DEMO_STACK_SIZE;
status = nx_packet_pool_create(&dhcp_client_pool, "DHCP Client Packet Pool",
NX_PACKET_SIZE, pointer, NX_PACKET_POOL_SIZE);
if (status != NX_SUCCESS) {
/* USER CODE BEGIN NX_Packet_Pool_Error */
Error_Handler();
/* USER CODE END NX_Packet_Pool_Error */
}
pointer = pointer + NX_PACKET_POOL_SIZE;
status = nx_ip_create(&client_ip, "DHCP Client IP Instance", IP_ADDRESS(0, 0, 0, 0),
IP_ADDRESS(255, 255, 255, 0), &dhcp_client_pool, nx_stm32_eth_driver,
pointer, 2048, 1);
if (status != NX_SUCCESS) {
/* USER CODE BEGIN NX_IP_Create_Error */
Error_Handler();
/* USER CODE END NX_IP_Create_Error */
}
pointer = pointer + 2048;
status = nx_arp_enable(&client_ip, pointer, 1024);
if (status != NX_SUCCESS) {
/* USER CODE BEGIN NX_ARP_Enable_Error */
Error_Handler();
/* USER CODE END NX_ARP_Enable_Error */
}
pointer = pointer + 1024;
status = nx_udp_enable(&client_ip);
if (status != NX_SUCCESS) {
/* USER CODE BEGIN NX_UDP_Enable_Error */
Error_Handler();
/* USER CODE END NX_UDP_Enable_Error */
}
// status =nx_icmp_enable(&client_ip);
// if (status != NX_SUCCESS) {
// /* USER CODE BEGIN NX_ICMP_Enable_Error */
// Error_Handler();
// /* USER CODE END NX_ICMP_Enable_Error */
// }
/* USER CODE END 0 */
/* USER CODE BEGIN MX_NetXDuo_Init */
/* USER CODE END MX_NetXDuo_Init */
return status;
}
/* USER CODE BEGIN 1 */
void dhcp_client_thread_entry(ULONG thread_input){
UINT status = TX_SUCCESS;
ULONG actual_status;
UINT length;
UINT ping = NX_TRUE;
UINT run_dhcp_client = NX_TRUE;
NX_PACKET *my_packet;
NX_PARAMETER_NOT_USED(thread_input);
do {
/* Get the link status. */
status = nx_ip_status_check(&client_ip, NX_IP_LINK_ENABLED,
&actual_status, 100);
} while (status != NX_SUCCESS);
status = nx_ip_interface_mtu_set(&client_ip,NX_DHCP_INTERFACE_INDEX, 1600);
if(status != NX_SUCCESS) {
Error_Handler();
}
status = nx_dhcp_create(&dhcp_client,&client_ip, "DHCP Client");
if(status != NX_SUCCESS) {
Error_Handler();
}
// status = nx_dhcp_state_change_notify(&dhcp_client, dhcp_state_change_CB);
// if(status != NX_SUCCESS) {
// Error_Handler();
// }
// status = nx_dhcp_set_interface_index(&dhcp_client, NX_DHCP_INTERFACE_INDEX);
// if(status != NX_SUCCESS) {
// Error_Handler();
// }
// status = nx_dhcp_interface_enable(&dhcp_client, NX_DHCP_INTERFACE_INDEX);
// if(status != NX_SUCCESS && status != NX_DHCP_INTERFACE_ALREADY_ENABLED) {
// Error_Handler();
// }
nx_dhcp_start(&dhcp_client);
while(run_dhcp_client) {
do{
status = nx_ip_status_check(&client_ip, NX_IP_ADDRESS_RESOLVED,
&actual_status, NX_IP_PERIODIC_RATE);
if(actual_status){
tx_thread_sleep(NX_IP_PERIODIC_RATE);
}
}while(actual_status != NX_SUCCESS || status != NX_SUCCESS);
length = sizeof(message);
BSP_LED_On(LED_GREEN);
while(ping){
status = nx_icmp_ping(&client_ip, NX_DHCP_DEFAULT_GATEWAY, (char *)message, length, &my_packet, NX_IP_PERIODIC_RATE);
if(status == NX_SUCCESS) {
nx_packet_release(my_packet);
}else{
dhcp_client_error_counter++;
}
dhcp_client_thread_counter++;
tx_thread_sleep(NX_IP_PERIODIC_RATE);
}
}
nx_dhcp_delete(&dhcp_client);
}
// void dhcp_state_change_CB(NX_DHCP *dhcp_ptr, UCHAR new_state){
// ULONG server_address;
// UINT status = TX_SUCCESS;
// NX_PARAMETER_NOT_USED(dhcp_ptr);
// NX_PARAMETER_NOT_USED(new_state);
// dhcp_client_state_changes++;
//
// if(new_state == NX_DHCP_STATE_SELECTING){
// status = nx_dhcp_request_client_ip(dhcp_ptr);
// }
// }
The commented code has been used in the different test to find what happends.
Thanks in advance for the help
Isidre
