Select one of the symbols to view example projects that use it.
 
Outline
Main_thread
Semaphore
EthPool
WebServerPool
EthIP
DHCPClient
HTTPServer
IPAddress
NetMask
SDMedia
media_memory
nx_server_pool
MX_NetXDuo_Init(void *)
ip_address_change_notify_callback(NX_IP *, void *)
webserver_request_notify_callback(NX_WEB_HTTP_SERVER *, UINT, CHAR *, NX_PACKET *)
nx_server_thread_entry(ULONG)
#include "app_netxduo.h"
#include "main.h"
#include "nxd_dhcp_client.h"
#include "nx_web_http_server.h"
#include "app_filex.h"
#include "ux_api.h"
#include "ux_network_driver.h"
Private typedef
Private define
#define TOGGLE_GREEN_LED
Private macro
Private variables
Private function prototypes
Files
loading...
CodeScopeSTM32 Libraries and SamplesUx_Device_CDC_ECMNetXDuo/App/app_netxduo.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file app_netxduo.c * @author MCD Application Team * @brief NetXDuo applicative file ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "app_netxduo.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "main.h" #include "nxd_dhcp_client.h" #include "nx_web_http_server.h" #include "app_filex.h" #include "ux_api.h" #include "ux_network_driver.h" 7 includes /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* Define the ThreadX , NetX and FileX object control blocks. */ /* Define Threadx global data structures. */ TX_THREAD Main_thread; TX_SEMAPHORE Semaphore; /* Define NetX global data structures. */ NX_PACKET_POOL EthPool; NX_PACKET_POOL WebServerPool; NX_IP EthIP; NX_DHCP DHCPClient; NX_WEB_HTTP_SERVER HTTPServer; ULONG IPAddress; ULONG NetMask; /* Define FileX global data structures. */ /* the web server reads the web content from the uSD, a FX_MEDIA instance is required */ FX_MEDIA SDMedia; uint32_t media_memory[512]; /* USER CODE END PTD */ Private typedef /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ #define TOGGLE_GREEN_LED "led=ToggleGreen" /* USER CODE END PD */ Private define /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ Private macro /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* Set nx_server_pool */ static uint8_t nx_server_pool[SERVER_POOL_SIZE]; /* USER CODE END PV */ Private variables /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ /* WEB HTTP server thread entry */ static void nx_server_thread_entry(ULONG thread_input); /* DHCP state change notify callback */ static VOID ip_address_change_notify_callback(NX_IP *ip_instance, VOID *ptr); /* Web Server callback when a new request from a web client is triggered */ static UINT webserver_request_notify_callback(NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr); /* USER CODE END PFP */ /** * @brief Application NetXDuo Initialization. * @param memory_ptr: memory pointer * @retval int *//* ... */ UINT MX_NetXDuo_Init(VOID *memory_ptr) { UINT ret = NX_SUCCESS; TX_BYTE_POOL *byte_pool = (TX_BYTE_POOL*)memory_ptr; /* USER CODE BEGIN MX_NetXDuo_MEM_POOL */ /* USER CODE END MX_NetXDuo_MEM_POOL */ /* USER CODE BEGIN MX_NetXDuo_Init */ /* Web App memory pointer. */ UCHAR *web_app_pointer; /* Initialize the NetXDuo system. */ nx_system_initialize(); /* Allocate the web stack instance. */ ret = tx_byte_allocate(byte_pool, (VOID **) &web_app_pointer, WEB_STACK_SIZE, TX_NO_WAIT); /* Check web stack allocation */ if (ret != TX_SUCCESS) { printf("Web stack allocation failed: 0x%02x\n", ret); Error_Handler(); }if (ret != TX_SUCCESS) { ... } /* Create the main thread. */ ret = tx_thread_create(&Main_thread, "Main_thread", nx_server_thread_entry, ENTRY_INPUT, web_app_pointer, WEB_STACK_SIZE, DEFAULT_PRIORITY, THREAD_PREEMPT_THRESHOLD, TX_NO_TIME_SLICE, TX_AUTO_START); /* Check Main Thread creation */ if (ret != TX_SUCCESS) { printf("Main Thread creation failed: 0x%02x\n", ret); Error_Handler(); }if (ret != TX_SUCCESS) { ... } /* Allocate the packet pool. */ ret = tx_byte_allocate(byte_pool, (VOID **) &web_app_pointer, NX_PACKET_POOL_SIZE, TX_NO_WAIT); /* Check packet pool allocation */ if (ret != TX_SUCCESS) { printf("Packet pool allocation failed: 0x%02x\n", ret); Error_Handler(); }if (ret != TX_SUCCESS) { ... } /* Create a packet pool. */ ret = nx_packet_pool_create(&EthPool, "NetX Main Packet Pool", PACKET_PAYLOAD_SIZE, web_app_pointer, NX_PACKET_POOL_SIZE); /* Check for packet pool creation status. */ if (ret != NX_SUCCESS) { printf("Packed creation failed : 0x%02x\n", ret); Error_Handler(); }if (ret != NX_SUCCESS) { ... } /* Create the server packet pool. */ ret = nx_packet_pool_create(&WebServerPool, "HTTP Server Packet Pool", SERVER_PACKET_SIZE, nx_server_pool, SERVER_POOL_SIZE); /* Check for server pool creation status. */ if (ret != NX_SUCCESS) { printf("Server pool creation failed : 0x%02x\n", ret); Error_Handler(); }if (ret != NX_SUCCESS) { ... } /* Allocate the IP instance. */ ret = tx_byte_allocate(byte_pool, (VOID **) &web_app_pointer, IP_MEMORY_SIZE, TX_NO_WAIT); /* Check for IP instance pool Allocation status. */ if (ret != NX_SUCCESS) { printf("IP instance Allocation failed : 0x%02x\n", ret); Error_Handler(); }if (ret != NX_SUCCESS) { ... } /* Create an IP instance by linking the ux network driver */ ret = nx_ip_create(&EthIP, "NetX IP Instance 0", NULL_IP_ADDRESS, NULL_IP_ADDRESS, &EthPool, _ux_network_driver_entry, web_app_pointer, IP_MEMORY_SIZE, DEFAULT_PRIORITY); /* Check the IP instance creation */ if (ret != NX_SUCCESS) { printf("IP Instance creation failed : 0x%02x\n", ret); Error_Handler(); }if (ret != NX_SUCCESS) { ... } /* Allocate the arp cache memory. */ ret = tx_byte_allocate(byte_pool, (VOID **) &web_app_pointer, ARP_CACHE_SIZE, TX_NO_WAIT); /* Check the arp cache memory Allocation status. */ if (ret != NX_SUCCESS) { printf("IP instance Allocation failed : 0x%02x\n", ret); Error_Handler(); }if (ret != NX_SUCCESS) { ... } /* Enable ARP and supply ARP cache memory for IP Instance 0. */ ret = nx_arp_enable(&EthIP, (void *) web_app_pointer, ARP_CACHE_SIZE); /* Check the ARP instance activation */ if (ret != NX_SUCCESS) { printf("ARP Enable for IP error : 0x%02x\n", ret); Error_Handler(); }if (ret != NX_SUCCESS) { ... } /* Enable the ICMP support to be able to ping the board */ ret = nx_icmp_enable(&EthIP); /* Check the ICMP activation */ if (ret != NX_SUCCESS) { printf("ICMP enable for IP error : 0x%02x\n", ret); Error_Handler(); }if (ret != NX_SUCCESS) { ... } /* Enable UDP support needed by DHCP client */ ret = nx_udp_enable(&EthIP); /* Check UDP support activation */ if (ret != NX_SUCCESS) { printf("UDP enable for IP error : 0x%02x\n", ret); Error_Handler(); }if (ret != NX_SUCCESS) { ... } /* Enable the TCP protocol */ ret = nx_tcp_enable(&EthIP); /* Check the TCP activation */ if (ret != NX_SUCCESS) { printf("TCP enable for IP error : 0x%02x\n", ret); Error_Handler(); }if (ret != NX_SUCCESS) { ... } /* Allocate the SERVER_STACK memory . */ ret = tx_byte_allocate(byte_pool, (VOID **) &web_app_pointer, SERVER_STACK, TX_NO_WAIT); /* Check the SERVER_STACK memory Allocation status. */ if (ret != NX_SUCCESS) { printf("Server stack Allocation failed : 0x%02x\n", ret); Error_Handler(); }if (ret != NX_SUCCESS) { ... } /* Create the HTTP Server. */ ret = nx_web_http_server_create(&HTTPServer, "WEB HTTP Server", &EthIP, CONNECTION_PORT, &SDMedia, web_app_pointer, SERVER_STACK, &WebServerPool, NX_NULL, webserver_request_notify_callback); /* Check the web server creation */ if (ret != NX_SUCCESS) { printf("HTTP WEB Server creation failed: 0x%02x\n", ret); Error_Handler(); }if (ret != NX_SUCCESS) { ... } /* Create the DHCP instance. */ ret = nx_dhcp_create(&DHCPClient, &EthIP, "dhcp_client"); /* Check the DHCP instance creation */ if (ret != NX_SUCCESS) { printf("DHCP Instance creation failed : 0x%02x\n", ret); }if (ret != NX_SUCCESS) { ... } /* Register a callback function for ip notify */ ret = nx_ip_address_change_notify(&EthIP, ip_address_change_notify_callback, NULL); /* Check the callback function creation*/ if (ret != NX_SUCCESS) { Error_Handler(); }if (ret != NX_SUCCESS) { ... } /* Create semaphore */ ret = tx_semaphore_create(&Semaphore, "App Semaphore", 0); /* Check semaphore creation */ if (ret != TX_SUCCESS) { printf("Semaphore creation failed : 0x%02x\n", ret); Error_Handler(); }if (ret != TX_SUCCESS) { ... } /* USER CODE END MX_NetXDuo_Init */ return ret; }MX_NetXDuo_Init (VOID *memory_ptr) { ... } /* USER CODE BEGIN 1 */ /** * @brief ip address change callback * @param ip_instance : NX_IP instance registered for this callback * @param ptr : VOID * optional data pointer * @retval None *//* ... */ static VOID ip_address_change_notify_callback(NX_IP *ip_instance, VOID *ptr) { /* as soon as the IP address is ready, the semaphore is released to let the web server start */ tx_semaphore_put(&Semaphore); }ip_address_change_notify_callback (NX_IP *ip_instance, VOID *ptr) { ... } UINT webserver_request_notify_callback(NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr) { CHAR request_data[256] = {0}; UINT request_size = 0; UINT status; /* * At each new request we toggle the green led, but in a real use case this callback can serve * to trigger more advanced tasks, like starting background threads or gather system info * and append them into the web page. *//* ... */ /* Get the requested data from packet */ status = nx_web_http_server_content_get(server_ptr, packet_ptr, 0, request_data, 100, &request_size); /* Check get data */ if (status == NX_SUCCESS) { /* Check if requested data equal TOGGLE_GREEN_LED */ if (strncmp((char const *)request_data, TOGGLE_GREEN_LED, sizeof(TOGGLE_GREEN_LED)) == 0) { BSP_LED_Toggle(LED_GREEN); }if (strncmp((char const *)request_data, TOGGLE_GREEN_LED, sizeof(TOGGLE_GREEN_LED)) == 0) { ... } }if (status == NX_SUCCESS) { ... } return NX_SUCCESS; }webserver_request_notify_callback (NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr) { ... } /** * @brief Application thread for HTTP web server * @param thread_input : thread input * @retval None *//* ... */ void nx_server_thread_entry(ULONG thread_input) { /* Sleep for 1s */ tx_thread_sleep(MS_TO_TICK(1000)); /* HTTP WEB SERVER THREAD Entry */ UINT status; NX_PARAMETER_NOT_USED(thread_input); printf("Starting DHCP client...\n"); /* Start the DHCP Client. */ status = nx_dhcp_start(&DHCPClient); /* Check DHCP Client Starting status. */ if (status != NX_SUCCESS) { /* Print DHCP Instance creation error. */ printf("DHCP Instance Starting error : 0x%02x\n", status); }if (status != NX_SUCCESS) { ... } /* Check if the semaphore is released */ if (tx_semaphore_get(&Semaphore, TX_WAIT_FOREVER) != TX_SUCCESS) { Error_Handler(); }if (tx_semaphore_get(&Semaphore, TX_WAIT_FOREVER) != TX_SUCCESS) { ... } /* Checks for errors in the IP address */ nx_ip_address_get(&EthIP, &IPAddress, &NetMask); /* Log IP address */ PRINT_ADDRESS(IPAddress); /* Log NetMask */ PRINT_ADDRESS(NetMask); /* Open the SD disk driver. */ status = fx_media_open(&SDMedia, "STM32_SDIO_DISK", fx_stm32_sd_driver, SD_DRIVER_INFO_POINTER, (VOID *) media_memory, sizeof(media_memory)); /* Check the media opening status. */ if (status != FX_SUCCESS) { /* Print Media Opening error. */ printf("FX media opening failed : 0x%02x\n", status); /* Error, call error handler.*/ Error_Handler(); }if (status != FX_SUCCESS) { ... } else { /* Print Media Opening Success. */ printf("Fx media successfully opened.\n"); }else { ... } /* Start the WEB HTTP Server. */ status = nx_web_http_server_start(&HTTPServer); /* Check the WEB HTTP Server starting status. */ if (status != NX_SUCCESS) { /* Print HTTP WEB Server starting error. */ printf("HTTP WEB Server Starting Failed, error: 0x%02x\n", status); /* Error, call error handler.*/ Error_Handler(); }if (status != NX_SUCCESS) { ... } else { /* Print HTTP WEB Server Starting success. */ printf("HTTP WEB Server successfully started.\n"); }else { ... } }nx_server_thread_entry (ULONG thread_input) { ... } Private function prototypes/* USER CODE END 1 */