{"id":5955,"date":"2020-05-04T11:15:57","date_gmt":"2020-05-04T18:15:57","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=5955"},"modified":"2020-05-27T11:43:07","modified_gmt":"2020-05-27T18:43:07","slug":"creating-and-debugging-wi-fi-http-server-with-the-rs14100-module","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/rs14100\/","title":{"rendered":"Creating and Debugging a Wi-Fi HTTP Server with the RS14100 Module"},"content":{"rendered":"<p>This tutorial shows how to create a basic Wi-Fi HTTP server using the <a href=\"https:\/\/www.redpinesignals.com\/Products\/wireless_secure_MCU\/Multi-Protocol_Wireless_Secure_MCU_SoCs_&amp;_Modules\/\">RS14100 wireless module<\/a>. We will create a basic project based on the <strong>access_point <\/strong>sample from the RS14100 SDK, will show how to build and debug it, and will then modify the sample to act as a basic HTTP server.<\/p>\n<p>Before you begin, install VisualGDB 5.5 or later, and make sure you have the latest updates via <strong>Tools-&gt;VisualGDB-&gt;Manage VisualGDB Packages<\/strong>.<\/p>\n<ol>\n<li>Start Visual Studio and select &#8220;File-&gt;New Project&#8221;. Then pick the VisualGDB Embedded Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5956\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/01-newprj.png\" alt=\"\" width=\"966\" height=\"624\" \/><\/a><\/li>\n<li>Enter the name and location for the new project, then press &#8220;Create&#8221; to launch the VisualGDB-specific part of the wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/02-path.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5957\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/02-path.png\" alt=\"\" width=\"966\" height=\"624\" \/><\/a><\/li>\n<li>Proceed with the default project type and build subsystem (Embedded Binary -&gt; MSBuild):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/03-binary.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5958\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/03-binary.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>On the next page pick the default ARM toolchain and select the RS14100 module in the list. Click &#8220;install&#8221; to automatically download and install the RS14100 support files:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/04-target.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5959\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/04-target.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>The next page of the wizard allows selecting a sample. In this tutorial we will use the &#8220;Access Point&#8221; sample from the &#8220;Basic samples&#8221; view:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/05-sample.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5960\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/05-sample.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a> You can also explore various samples from the RS14100 SDK by switching to the &#8220;RS14100 SDK Samples&#8221; view. They will build out-of-the-box, however we have not tested them on the hardware.<\/li>\n<li>Connect your board to an JTAG\/SWD debugger, and make sure both the board and the debugger are powered on.<br \/>\n<strong>WARNING: In this tutorial we will use the CMSIS-DAP debugger that comes with the RS14100 evaluation board, however it is known to be relatively unreliable and have random connectivity problems. If you are not able to debug the board using it, please try a different SWD-capable debugger and a different SWD cable. <\/strong>You can find instructions for connecting different JTAG\/SWD debuggers on <a href=\"https:\/\/visualgdb.com\/documentation\/rs14100\/wiring\/\">this page<\/a>.<\/li>\n<li>Once the debugger is connected to USB, VisualGDB will automatically detect it and configure OpenOCD. If you encounter problems, make sure the debug protocol is set to SWD and the &#8220;<strong>Reset device after programming<\/strong>&#8221; checkbox is checked:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/06-debug-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5977\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/06-debug-1.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a>If you are using Segger J-Link and the J-Link GDB Stub does not support RS14100, simply select <strong>OpenOCD<\/strong> instead of <strong>J-Link Software<\/strong> on the Debug Settings page and you will still be able to debug RS14100 with it.<\/li>\n<li>Press the &#8220;<strong>Test<\/strong>&#8221; button to verify the debugging setup. Note that VisualGDB will warn about zero values for most registers:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/07-wiring.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5962\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/07-wiring.png\" alt=\"\" width=\"999\" height=\"693\" \/><\/a>This is normal for RS14100 devices and can be ignored, as long as there are no other errors.<\/li>\n<li>Press &#8220;Finish&#8221; to create the project. Then, set a breakpoint in the <strong>rsi_ap_start()<\/strong> function at the call to <strong>rsi_wireless_init() <\/strong>and press F5 to build the project and start debugging it: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/08-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5963\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/08-bkpt.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>Before we can do any meaningful debugging, we will first adjust the project to display diagnostic output (including the correct IP address) via the fast semihosting interface. Stop debugging by pressing Shift-F5 and open VisualGDB Project Properties -&gt; Embedded Frameworks. Then, reference the &#8220;<strong>Fast Semihosting and Embedded Profiler<\/strong>&#8221; framework:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/09-profiler.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5964\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/09-profiler.png\" alt=\"\" width=\"889\" height=\"598\" \/><\/a>You can also use the Embedded Frameworks page to reference various components of the RS14100 SDK. Each framework can be further tweaked using the &#8220;<strong>Framework Configuration<\/strong>&#8221; view.<\/li>\n<li>Now that we referenced the <strong>Fast Semihosting<\/strong> framework, we can modify the project to produce more debug output (note that unless each line ends with &#8220;\\n&#8221;,<strong> printf()<\/strong> won&#8217;t output it immediately):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/10-notify.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5965\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/10-notify.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>Locate the <strong>rsi_ap_start()<\/strong> function in the main source file. You can get a quick overview of the functions called by it via the CodeJumps link just on top of the function name:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/11-jumps.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5966\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/11-jumps.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>The function calls the RSI socket api (e.g. <strong>rsi_listen()<\/strong>, <strong>rsi_accept()<\/strong>, &#8230;) to listen to the incoming connections on a fixed TCP port. Once an incoming connection is received, it transfers some data and closes the connection. We will replace this logic with a very basic HTTP server that will continuously listen for connections on the given port and will print back the URL in response to each request. Replace the code after <strong>rsi_listen()<\/strong> with the following:\n<pre class=\"\">  printf(\"Listening on %d.%d.%d.%d:%d\\n\",\r\n         (ip_addr &gt;&gt; 0) &amp; 0xFF,\r\n         (ip_addr &gt;&gt; 8) &amp; 0xFF,\r\n         (ip_addr &gt;&gt; 16) &amp; 0xFF,\r\n         (ip_addr &gt;&gt; 24) &amp; 0xFF,\r\n         DEVICE_PORT);\r\n\r\n  static const char szHeader[] = \"HTTP\/1.0 200 OK\\r\\nContent-type: text\/html\\r\\n\\r\\n&lt;html&gt;&lt;body&gt;&lt;h1&gt;Hello, world&lt;\/h1&gt;Greetings from RS14100! You have requested the following URL: \";\r\n  static const char szFooter[] = \"&lt;\/body&gt;&lt;\/html&gt;\";\r\n\r\n  static volatile int RequestNumber = 0;\r\n  static volatile char LastURL[128] = {\r\n      0,\r\n  };\r\n\r\n  for (;;)\r\n  {\r\n      addr_size = sizeof(server_socket);\r\n      int client_sock = rsi_accept(server_socket, (struct sockaddr *)&amp;client_addr, &amp;addr_size);\r\n      RequestNumber++;\r\n      static char szBuf[4096];\r\n      int readPos = 0;\r\n      char *pURL;\r\n      if (client_sock &lt; 0)\r\n      {\r\n          asm(\"bkpt 255\");\r\n          continue;\r\n      }\r\n\r\n      \/\/Read the entire HTTP request\r\n      for (;;)\r\n      {\r\n          int done = rsi_recv(client_sock, szBuf + readPos, sizeof(szBuf) - readPos - 1, 0);\r\n          if (done &lt; 0 || done &gt;= (sizeof(szBuf) - readPos))\r\n              done = 0;\r\n          readPos += done;\r\n          szBuf[readPos] = 0;\r\n          if (strstr(szBuf, \"\\r\\n\\r\\n\"))\r\n              break;\r\n          if (!done)\r\n              break;\r\n      }\r\n\r\n      pURL = strchr(szBuf, ' ');\r\n      if (pURL)\r\n      {\r\n          char *pURLEnd = strchr(pURL + 1, ' ');\r\n          if (pURLEnd)\r\n          {\r\n              pURL++;\r\n              pURLEnd[0] = 0;\r\n              strncpy(LastURL, pURL, sizeof(LastURL) - 1);\r\n\r\n              rsi_send(client_sock, szHeader, sizeof(szHeader) - 1, 0);\r\n              rsi_send(client_sock, pURL, strlen(pURL), 0);\r\n              rsi_send(client_sock, szFooter, sizeof(szFooter) - 1, 0);\r\n          }\r\n      }\r\n\r\n      rsi_shutdown(client_sock, 0);\r\n  }<\/pre>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/12-newlogic.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5967\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/12-newlogic.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>To minimize compatibility problems with other devices, disable the the Wi-Fi security by setting <strong>SECURITY_TYPE<\/strong> to <strong>RSI_OPEN<\/strong>. Also set <strong>DEVICE_PORT<\/strong> to <strong>80<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/13-open.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5968\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/13-open.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>Build and run the project again. The ARM Semihosting Console will now show the debug output from the board, including the IP address where it is listening:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/14-listening.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5969\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/14-listening.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>Locate the <strong>REDPINE_AP<\/strong> wireless network on any Wi-Fi-capable computer and click &#8220;Connect&#8221; to establish a connection: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/15-connect.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5970\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/15-connect.png\" alt=\"\" width=\"356\" height=\"621\" \/><\/a><\/li>\n<li>Enter the IP address shown in the <strong>ARM Semihosting Console<\/strong> in the browser. You will see a basic page echoing back the URL: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/16-browser.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5971\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/16-browser.png\" alt=\"\" width=\"586\" height=\"308\" \/><\/a><\/li>\n<li>You can use the regular debugging techniques (e.g. breakpoints, stepping) to see what is going on on the device:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5978\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/bkpt.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>Note that stopping at a breakpoint for too long may cause network timeouts. In the rest of the tutorial we will show how to avoid it by using VisualGDB&#8217;s non-intrusive debugging techniques instead. Open the <strong>Debug-&gt;Windows-&gt;Live Watch<\/strong> view and switch it to Globals. VisualGDB will show the state of all global variables without stopping the program. E.g. you can see how the <strong>_dwTickCount<\/strong> variable keeps growing:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/17-tick.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5972\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/17-tick.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>Locate the <strong>LastURL<\/strong> variable in the list and switch its type to <strong>String<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/18-urlview.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5973\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/18-urlview.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>Then, enable the source code annotations in the Live Watch toolbar. VisualGDB will show the value of <strong>RequestNumber<\/strong> and <strong>LastURL<\/strong> directly in the code: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/19-label.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5974\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/19-label.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>As soon as you request a new URL, the variables will be immediately updated without having to stop the target, or causing any additional latency: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/20-testurl.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5975\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/20-testurl.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>Finally, we will show how to see which branches of the program get executed without setting any breakpoints. Open VisualGDB Project Properties and enable Live Coverage:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/01-cov.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5979\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/01-cov.png\" alt=\"\" width=\"889\" height=\"598\" \/><\/a><\/li>\n<li>Note that this will considerably increase the FLASH and RAM usage, as GCC will instrument every branch in the program to count the number of times it&#8217;s taken. You can reduce the memory overhead by disabling instrumentation for individual files via <a href=\"https:\/\/visualgdb.com\/documentation\/projects\/msbuild\/\">MSBuild Properties<\/a>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/02-size.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5980\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/02-size.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<li>The Live Coverage will show how many times and how long ago each function was executed, and will also highlight recently executed lines, so you can see what is going on without setting any breakpoints:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/03-live.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5981\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/05\/03-live.png\" alt=\"\" width=\"1183\" height=\"759\" \/><\/a><\/li>\n<\/ol>\n<p>You can find the source code shown in this tutorial in our <a href=\"https:\/\/github.com\/sysprogs\/tutorials\/tree\/master\/visualgdb\/ARM\/boards\/RS14100\/RS14100Demo\">GitHub repository<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to create a basic Wi-Fi HTTP server using the RS14100 wireless module. We will create a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[53,56,59,102],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5955"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=5955"}],"version-history":[{"count":8,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5955\/revisions"}],"predecessor-version":[{"id":6196,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5955\/revisions\/6196"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=5955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=5955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=5955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}