- void MX_ThreadX_Init(void)
- {
- /* USER CODE BEGIN Before_Kernel_Start */
- /* USER CODE END Before_Kernel_Start */
- tx_kernel_enter();
- /* USER CODE BEGIN Kernel_Start_Error */
- /* USER CODE END Kernel_Start_Error */
- }
tx_kernel_enter();//ThreadX入口
3、app_azure_rtos.c
VOID tx_application_define(VOID *first_unused_memory)
中调用了:
status = MX_FileX_Init(memory_ptr);//处理网页读取
status = MX_NetXDuo_Init(memory_ptr);//处理网络相关
4、app_netxduo.c
UINT MX_NetXDuo_Init(VOID *memory_ptr)
中执行了:
ret = tx_thread_create(&AppMainThread, AppMainThreadName, App_Main_Thread_Entry,
(ULONG)byte_pool, stack_ptr, stack_size,
MAIN_THREAD_PRIORITY, MAIN_THREAD_PRIORITY, TX_NO_TIME_SLICE, TX_AUTO_START);
ret = tx_thread_create(&AppMain2Thread, AppMain2ThreadName, App_Main2_Thread_Entry,
(ULONG)byte_pool, stack_ptr, stack_size,
MAIN2_THREAD_PRIORITY, MAIN2_THREAD_PRIORITY, TX_NO_TIME_SLICE, TX_AUTO_START);
ret = tx_thread_create(&AppIperfThread, AppIperfThreadName, App_Iperf_Thread_Entry,
(ULONG)byte_pool, stack_ptr, stack_size,
APP_IPERF_THREAD_PRIORITY, APP_IPERF_THREAD_PRIORITY, TX_NO_TIME_SLICE, TX_DONT_START);
生成了几个线程,其中App_Iperf_Thread_Entry生成了一个Iperf网络测试界面供浏览器访问。
- static VOID App_Iperf_Thread_Entry(ULONG thread_input)
- {
- TX_BYTE_POOL *const byte_pool = (TX_BYTE_POOL *) thread_input;
- MSG_DEBUG("[%06" PRIu32 "]>\n", HAL_GetTick());
- {
- MSG_INFO(" - Device Name : %s.\n", wifi_obj_get()->SysInfo.Product_Name);
- MSG_INFO(" - Device ID : %s.\n", wifi_obj_get()->SysInfo.Product_ID);
- MSG_INFO(" - Device Version : %s.\n", wifi_obj_get()->SysInfo.FW_Rev);
- MSG_INFO(" - MAC address : %02X.%02X.%02X.%02X.%02X.%02X\n",
- wifi_obj_get()->SysInfo.MAC[0], wifi_obj_get()->SysInfo.MAC[1],
- wifi_obj_get()->SysInfo.MAC[2], wifi_obj_get()->SysInfo.MAC[3],
- wifi_obj_get()->SysInfo.MAC[4], wifi_obj_get()->SysInfo.MAC[5]);
- }
- /* The network is correctly initialized, start the Iperf utility. */
- /* Allocate the memory for HTTP and Iperf stack */
- {
- const ULONG http_stack_size = NX_IPERF_HTTP_STACK_SIZE;
- UCHAR *http_stack;
- const ULONG iperf_stack_size = NX_IPERF_STACK_SIZE;
- UCHAR *iperf_stack;
- if (tx_byte_allocate(byte_pool, (VOID **)&http_stack, http_stack_size, TX_NO_WAIT) != TX_SUCCESS)
- {
- MSG_ERROR("Allocation failed!\n");
- Error_Handler();
- }
- if (tx_byte_allocate(byte_pool, (VOID **)&iperf_stack, iperf_stack_size, TX_NO_WAIT) != TX_SUCCESS)
- {
- MSG_ERROR("Allocation failed!\n");
- Error_Handler();
- }
- MSG_INFO("\n##### Please open a browser window with the Target board's IP address\n\n");
- /* Application body. */
- nx_iperf_entry(&IperfPacketPool, &IpInstance, http_stack, http_stack_size, iperf_stack, iperf_stack_size);
- }
- }
程序运行起来打印的日志:
浏览器访问返回:
5、与模块相关的配置:
mx_wifi_conf.h
- #define MX_WIFI_USE_SPI (1)
- #define WIFI_SSID "SSID"
- #define WIFI_PASSWORD "PASSWORD"
6、网页内容定义
nx_iperf.h
- #define htmlresponse "HTTP/1.0 200 \r\nContent-Type: text/html\r\n\r\n"
- #define htmltag "<HTML>"
- #define htmlendtag "</HTML>"
- #define titleline "<HEAD><TITLE>NetX IPerf Demonstration</TITLE></HEAD>\r\n"
- #define bodytag "<body bgcolor="#000000">\r\n"
- #define bodyendtag "</body>\r\n"
- #define **_area \
- "<table border=0 align=center width=90%><tr>" \
- "<td width=30%><img align=left src=ms**.jpg>" \
- "</td><td width=33%></td><td width=33%><img align=right src=nx**.png></td></tr></table>"
- #define hrline "<HR SIZE=6 WIDTH="90%" NOSHADE COLOR="#FFFF00">"
- #define h1line1 " <H1><font face=arial color="#FFFFFF">NetX IP Address: "
- #define h1line2 "</font></H1><br>\r\n"
- #define tabletag "<table height=50%>"
最后
由于个人能力有限,而且例程篇幅过长不做一一解读了,如果有兴趣可以通过MX生成代码解读。
SPI接口WIFI模块不常见,而且ST在实现上运用了ThreadX、NetXDuo等技术,而且封装了和模块通信的协议,再加上防御性编程,感觉远比驱动一般串口WFI模块复杂,甚至可以说不比直接通过WIFI模块二次开发简单。
终于跑通了,再无心魔,念头通达,修为又可以提升了。