Commit 848c884f authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by rojer

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
parent 0769bbb7
......@@ -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();
......
......@@ -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"));
......
......@@ -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();
}
......@@ -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_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment