Skip to content

Commit 7945187

Browse files
committed
debugging, it works ish
1 parent b4f0203 commit 7945187

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

NetX/inc/u_nx_ethernet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,7 @@ uint32_t ethernet_mqtt_publish(char* topic_name, UINT topic_size, char* message,
124124
*/
125125
NX_PTP_DATE_TIME ethernet_get_time(void);
126126

127+
UINT ethernent_print_arp_status(void);
128+
127129
// clang-format on
128130
#endif /* u_nx_ethernet.h */

NetX/src/u_nx_ethernet.c

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "u_nx_ethernet.h"
33
#include "nx_stm32_eth_driver.h"
44
#include "nxd_ptp_client.h"
5+
#include "tx_api.h"
56
#include "u_nx_debug.h"
67
#include "u_tx_debug.h"
78
#include "c_utils.h"
@@ -14,8 +15,8 @@
1415
#endif
1516

1617
/* PRIVATE MACROS */
17-
#define _IP_THREAD_STACK_SIZE 2048
18-
#define _ARP_CACHE_SIZE 1024
18+
#define _IP_THREAD_STACK_SIZE 4096
19+
#define _ARP_CACHE_SIZE 2048
1920
#define _IP_THREAD_PRIORITY 1
2021
#define _IP_NETWORK_MASK IP_ADDRESS(255, 255, 255, 0)
2122
#define _UDP_QUEUE_MAXIMUM 12
@@ -210,6 +211,15 @@ UINT ethernet_init(ethernet_node_t node_id, DriverFunction driver, OnRecieve on_
210211
return status;
211212
}
212213

214+
// behold the magic
215+
// this is a poll function to wait until the driver has completely initialized
216+
// without it the arp module and the TCP module fail silently and confusingly
217+
ULONG current_status;
218+
do {
219+
nx_ip_driver_direct_command(&device.ip, 51, &current_status);
220+
tx_thread_sleep(100);
221+
} while (current_status != 4);// NX_DRIVER_STATE_LINK_ENABLED
222+
213223
/* Enable ARP */
214224
status = nx_arp_enable(
215225
&device.ip, // IP instance
@@ -372,11 +382,6 @@ UINT ethernet_init(ethernet_node_t node_id, DriverFunction driver, OnRecieve on_
372382
/* Mark device as initialized. */
373383
device.is_initialized = true;
374384

375-
ETH_MACFilterConfigTypeDef filter;
376-
HAL_ETH_GetMACFilterConfig(&heth, &filter);
377-
filter.BroadcastFilter = DISABLE;
378-
HAL_ETH_SetMACFilterConfig(&heth, &filter);
379-
380385
PRINTLN_INFO("Ran ethernet_init().");
381386
return NX_SUCCESS;
382387
}
@@ -507,4 +512,31 @@ NX_PTP_DATE_TIME ethernet_get_time(void) {
507512
return date;
508513
}
509514

515+
UINT ethernet_print_arp_status(void) {
516+
ULONG arp_requests_sent = 100;
517+
ULONG arp_requests_received = 100;
518+
519+
ULONG arp_responses_sent = 100;
520+
ULONG arp_responses_received;
521+
ULONG arp_dynamic_entries= 100;
522+
ULONG arp_static_entries= 100;
523+
ULONG arp_aged_entries= 100;
524+
ULONG arp_invalid_messages= 100;
525+
UINT status = nx_arp_info_get(&device.ip, &arp_requests_sent, &arp_requests_received,
526+
&arp_responses_sent, &arp_responses_received,
527+
&arp_dynamic_entries, &arp_static_entries,
528+
&arp_aged_entries, &arp_invalid_messages);
529+
if(status != NX_SUCCESS) {
530+
PRINTLN_ERROR("Failed to retrieve ARP info (Status: %d/%s)", status, nx_status_toString(status));
531+
return status;
532+
}
533+
PRINTLN_INFO("ARP info REQ SENT %lu, REQ RECV %lu, RESP SENT %lu, RESP RECV %lu, DYN ENTRY %lu, S ENTRY %lu, AGED %lu, INVALID %lu", arp_requests_sent, arp_requests_received,
534+
arp_responses_sent, arp_responses_received,
535+
arp_dynamic_entries, arp_static_entries,
536+
arp_aged_entries, arp_invalid_messages);
537+
538+
return status;
539+
}
540+
541+
510542
// clang-format on

0 commit comments

Comments
 (0)