From 848c884fff80de03051344e230392a68d4b51b84 Mon Sep 17 00:00:00 2001 From: Deomid Ryabkov <rojer@cesanta.com> Date: Fri, 15 Apr 2016 18:23:14 +0200 Subject: [PATCH] Make sure NWP is stopped before sl_Start In SDK 1.2.0 TI decided to stop resetting NWP before sl_Start, which in practice means that sl_start will hang on subsequent runs after the first. See this post for details and suggested solution: https://e2e.ti.com/support/wireless_connectivity/simplelink_wifi_cc31xx_cc32xx/f/968/p/499123/1806610#1806610 However, since they don't provide OS_debug variant of simplelink.a and adding another project dependency will complicate our demo even more, we just take the required bit of code. PUBLISHED_FROM=c729c0fcbb240aa90a716edd43888de5881d6731 --- examples/CC3200/ccs/MG_hello/main.c | 15 ++++++--- examples/CC3200/main.c | 16 ++++++--- examples/CC3200/wifi.c | 50 +++++++++++++++++++++++++++++ examples/CC3200/wifi.h | 1 + 4 files changed, 73 insertions(+), 9 deletions(-) diff --git a/examples/CC3200/ccs/MG_hello/main.c b/examples/CC3200/ccs/MG_hello/main.c index 623082705..9d3df6fe3 100644 --- a/examples/CC3200/ccs/MG_hello/main.c +++ b/examples/CC3200/ccs/MG_hello/main.c @@ -42,7 +42,8 @@ #include "wifi.h" -static const char *upload_form = "\ +static const char *upload_form = + "\ <h1>Upload file</h1> \ <form action='/upload' method='POST' enctype='multipart/form-data'> \ <input type='file' name='file'> \ @@ -80,8 +81,7 @@ void mg_ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ("HTTP request from %s: %.*s %.*s", addr, (int) hm->method.len, hm->method.p, (int) hm->uri.len, hm->uri.p)); if (mg_vcmp(&hm->uri, "/upload") == 0 || - (mg_vcmp(&hm->uri, "/") == 0 && - mg_stat("SL:index.html", &st) != 0)) { + (mg_vcmp(&hm->uri, "/") == 0 && mg_stat("SL:index.html", &st) != 0)) { mg_send(nc, upload_form, strlen(upload_form)); nc->flags |= MG_F_SEND_AND_CLOSE; break; @@ -114,7 +114,14 @@ void mg_ev_handler(struct mg_connection *nc, int ev, void *ev_data) { static void mg_init(struct mg_mgr *mgr) { LOG(LL_INFO, ("MG task running")); - sl_Start(0, 0, 0); + stop_nwp(); /* See function description in wifi.c */ + int role = sl_Start(0, 0, 0); + if (role < 0) { + LOG(LL_ERROR, ("Failed to start NWP")); + return; + } + + LOG(LL_INFO, ("NWP started")); sl_fs_init(); diff --git a/examples/CC3200/main.c b/examples/CC3200/main.c index b44150e64..e071029c6 100644 --- a/examples/CC3200/main.c +++ b/examples/CC3200/main.c @@ -50,7 +50,8 @@ #define BM222_ADDR 0x18 #define TMP006_ADDR 0x41 -static const char *upload_form = "\ +static const char *upload_form = + "\ <h1>Upload file</h1> \ <form action='/upload' method='POST' enctype='multipart/form-data'> \ <input type='file' name='file'> \ @@ -88,8 +89,7 @@ static void mg_ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ("HTTP request from %s: %.*s %.*s", addr, (int) hm->method.len, hm->method.p, (int) hm->uri.len, hm->uri.p)); if (mg_vcmp(&hm->uri, "/upload") == 0 || - (mg_vcmp(&hm->uri, "/") == 0 && - mg_stat("SL:index.html", &st) != 0)) { + (mg_vcmp(&hm->uri, "/") == 0 && mg_stat("SL:index.html", &st) != 0)) { mg_send(nc, upload_form, strlen(upload_form)); nc->flags |= MG_F_SEND_AND_CLOSE; break; @@ -131,14 +131,20 @@ static void mg_ev_handler(struct mg_connection *nc, int ev, void *ev_data) { static void mg_init(struct mg_mgr *mgr) { LOG(LL_INFO, ("MG task running")); + + stop_nwp(); /* See function description in wifi.c */ + int role = sl_Start(0, 0, 0); + if (role < 0) { + LOG(LL_ERROR, ("Failed to start NWP")); + return; + } + LOG(LL_INFO, ("NWP started")); GPIO_IF_LedToggle(MCU_RED_LED_GPIO); data_init_sensors(TMP006_ADDR, BM222_ADDR); sl_fs_init(); - sl_Start(NULL, NULL, NULL); - #if defined(WIFI_STA_SSID) if (!wifi_setup_sta(WIFI_STA_SSID, WIFI_STA_PASS)) { LOG(LL_ERROR, ("Error setting up WiFi station")); diff --git a/examples/CC3200/wifi.c b/examples/CC3200/wifi.c index f8bfa112d..6c6d10812 100644 --- a/examples/CC3200/wifi.c +++ b/examples/CC3200/wifi.c @@ -2,11 +2,14 @@ #include "mongoose.h" +#include <simplelink/cc_pal.h> #include <simplelink/include/wlan.h> #include <inc/hw_types.h> #include <driverlib/gpio.h> +#include <driverlib/utils.h> + #include <example/common/gpio_if.h> void SimpleLinkWlanEventHandler(SlWlanEvent_t *e) { @@ -113,3 +116,50 @@ bool wifi_setup_sta(const char *ssid, const char *pass) { } return true; } + +/* + * In SDK 1.2.0 TI decided to stop resetting NWP before sl_Start, which in + * practice means that sl_start will hang on subsequent runs after the first. + * + * See this post for details and suggested solution: + * https://e2e.ti.com/support/wireless_connectivity/simplelink_wifi_cc31xx_cc32xx/f/968/p/499123/1806610#1806610 + * + * However, since they don't provide OS_debug variant of simplelink.a and + * adding another project dependency will complicate our demo even more, + * we just take the required bit of code. + * + * This is a copy-paste of NwpPowerOnPreamble from cc_pal.c. + */ +void stop_nwp(void) { +#define MAX_RETRY_COUNT 1000 + unsigned int sl_stop_ind, apps_int_sts_raw, nwp_lpds_wake_cfg; + unsigned int retry_count; + /* Perform the sl_stop equivalent to ensure network services + are turned off if active */ + HWREG(0x400F70B8) = 1; /* APPs to NWP interrupt */ + UtilsDelay(800000 / 5); + + retry_count = 0; + nwp_lpds_wake_cfg = HWREG(0x4402D404); + sl_stop_ind = HWREG(0x4402E16C); + + if ((nwp_lpds_wake_cfg != 0x20) && /* Check for NWP POR condition */ + !(sl_stop_ind & 0x2)) /* Check if sl_stop was executed */ + { + /* Loop until APPs->NWP interrupt is cleared or timeout */ + while (retry_count < MAX_RETRY_COUNT) { + apps_int_sts_raw = HWREG(0x400F70C0); + if (apps_int_sts_raw & 0x1) { + UtilsDelay(800000 / 5); + retry_count++; + } else { + break; + } + } + } + HWREG(0x400F70B0) = 1; /* Clear APPs to NWP interrupt */ + UtilsDelay(800000 / 5); + + /* Stop the networking services */ + NwpPowerOff(); +} diff --git a/examples/CC3200/wifi.h b/examples/CC3200/wifi.h index e300cbf49..982fa821b 100644 --- a/examples/CC3200/wifi.h +++ b/examples/CC3200/wifi.h @@ -10,5 +10,6 @@ bool wifi_setup_ap(const char *ssid, const char *pass, int channel); bool wifi_setup_sta(const char *ssid, const char *pass); +void stop_nwp(); #endif /* CS_MONGOOSE_EXAMPLES_CC3200_WIFI_H_ */ -- GitLab