Wifi: disabled mode, USB: BM/DAP mode, SWD: access lock

This commit is contained in:
SG 2022-12-05 20:34:54 +03:00
parent be1b987e35
commit 8732663f04
12 changed files with 195 additions and 53 deletions

View File

@ -1 +1 @@
main.svelte-bny5z.svelte-bny5z{border:4px dashed #000;margin:10px auto;padding:10px;max-width:800px;overflow:hidden}.svelte-bny5z.svelte-bny5z{-moz-user-select:none;-o-user-select:none;-khtml-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none}tabs.svelte-bny5z.svelte-bny5z{border-bottom:4px dashed #000;width:100%;display:block}tab.svelte-bny5z.svelte-bny5z{margin-right:10px;padding:5px 10px;margin-bottom:5px;display:inline-block}tab.svelte-bny5z.svelte-bny5z:hover,tab.selected.svelte-bny5z.svelte-bny5z:hover{background:rgb(255, 255, 255);color:#000000}tab.selected.svelte-bny5z.svelte-bny5z{background-color:black;color:white}tabs-content.svelte-bny5z.svelte-bny5z{display:block;margin-top:10px}error.svelte-bny5z.svelte-bny5z{padding:5px 10px;background-color:rgb(255, 0, 0);color:black}@font-face{font-family:"DOS";src:url("../assets/ega8.otf") format("opentype");font-weight:normal;font-style:normal;-webkit-font-kerning:none;font-kerning:none;font-synthesis:none;-webkit-font-variant-ligatures:none;font-variant-ligatures:none;font-variant-numeric:tabular-nums}body{padding:0;margin:0;background-color:#ffa21c;color:#000;font-size:28px;font-family:"DOS", monospace;line-height:1;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0, 0, 0, 0)}.grid.svelte-bny5z.svelte-bny5z{display:inline-grid;grid-template-columns:auto auto}.grid.svelte-bny5z>div.svelte-bny5z{margin-top:10px}.value-name.svelte-bny5z.svelte-bny5z{text-align:right}task-list.svelte-bny5z.svelte-bny5z{display:inline-grid;grid-template-columns:auto auto auto auto auto;width:100%}.input-text-css.svelte-4h7oz2{display:inline-block;color:#000;font-size:28px;font-family:"DOS", monospace;line-height:1;box-sizing:border-box;margin:0;border:0;border-bottom:4px solid #000;padding:0 5px 0 5px;box-shadow:none;border-radius:0;-moz-appearance:none;-webkit-appearance:none;appearance:none;background-color:#ffa21c;height:32px}.input-text-css.svelte-4h7oz2:focus-visible,.input-text-css.svelte-4h7oz2:hover{outline:0;background-color:white}@keyframes svelte-1471rey-spinner-animation{0%{content:"|"}25%{content:"/"}50%{content:"-"}75%{content:"\\"}100%{content:"|"}}spinner.svelte-1471rey::after{display:inline-block;animation:svelte-1471rey-spinner-animation 0.6s linear infinite alternate;content:"|"}popup-wrapper.svelte-1ufadaz{background-color:rgba(0, 0, 0, 0.863);width:100%;height:100%;display:table;table-layout:fixed;z-index:999;overflow:auto;position:fixed;top:0;left:0;right:0;bottom:0}popup-body.svelte-1ufadaz{margin:auto;display:table-cell;text-align:center;vertical-align:middle;width:100%}popup-content.svelte-1ufadaz{background-color:#ffa21c;display:inline-block;outline:none;position:relative;text-align:initial;max-width:100vw}popup-border.svelte-1ufadaz{display:block;border:4px dashed #000;margin:10px;padding:10px}popup-close.svelte-1ufadaz{background-color:#000;display:inline-block;color:#ffa21c;position:absolute;width:24px;right:0px;top:0px;text-align:center}popup-close.svelte-1ufadaz:hover{background-color:#fff;color:#000}.button.svelte-1rqr1h4{box-sizing:border-box;display:inline-block;font-size:28px;font-family:"DOS", monospace;line-height:1;border:0;padding:0 5px 0 5px;box-shadow:none;border-radius:0;display:inline-block;max-width:100%}.black.svelte-1rqr1h4{color:white;background-color:black;border-bottom:4px solid #000}.black.svelte-1rqr1h4:hover{background:#fff;color:#000}.normal.svelte-1rqr1h4{color:#000;background-color:#ffa21c;border-bottom:4px solid #ffa21c}.normal.svelte-1rqr1h4:hover{background:#000;color:#fff}select.svelte-1rf61qb.svelte-1rf61qb{display:inline-block;color:#000;font-size:28px;font-family:"DOS", monospace;line-height:1;box-sizing:border-box;margin:0;border:0;border-bottom:4px solid #000;padding:0 5px 0 5px;box-shadow:none;border-radius:0;-moz-appearance:none;-webkit-appearance:none;appearance:none;background-color:#ffa21c}select.svelte-1rf61qb.svelte-1rf61qb::-ms-expand{display:none}select.svelte-1rf61qb.svelte-1rf61qb:hover{background:rgb(255, 255, 255);color:#000000}select.svelte-1rf61qb.svelte-1rf61qb:focus{box-shadow:none;outline:none;background:rgb(255, 255, 255);color:#000000}select.svelte-1rf61qb option.svelte-1rf61qb{font-weight:normal}.button-css.svelte-yar6m3{background-color:black;color:white;font-size:28px;font-family:"DOS", monospace;line-height:1;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0, 0, 0, 0);border:0;padding:5px 10px;display:inline-block;max-width:100%}.button-css.svelte-yar6m3:hover{background:rgb(255, 255, 255);color:#000000}
main.svelte-bny5z.svelte-bny5z{border:4px dashed #000;margin:10px auto;padding:10px;max-width:800px;overflow:hidden}.svelte-bny5z.svelte-bny5z{-moz-user-select:none;-o-user-select:none;-khtml-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none}tabs.svelte-bny5z.svelte-bny5z{border-bottom:4px dashed #000;width:100%;display:block}tab.svelte-bny5z.svelte-bny5z{margin-right:10px;padding:5px 10px;margin-bottom:5px;display:inline-block}tab.svelte-bny5z.svelte-bny5z:hover,tab.selected.svelte-bny5z.svelte-bny5z:hover{background:rgb(255, 255, 255);color:#000000}tab.selected.svelte-bny5z.svelte-bny5z{background-color:black;color:white}tabs-content.svelte-bny5z.svelte-bny5z{display:block;margin-top:10px}error.svelte-bny5z.svelte-bny5z{padding:5px 10px;background-color:rgb(255, 0, 0);color:black}@font-face{font-family:"DOS";src:url("../assets/ega8.otf") format("opentype");font-weight:normal;font-style:normal;-webkit-font-kerning:none;font-kerning:none;font-synthesis:none;-webkit-font-variant-ligatures:none;font-variant-ligatures:none;font-variant-numeric:tabular-nums}body{padding:0;margin:0;background-color:#ffa21c;color:#000;font-size:28px;font-family:"DOS", monospace;line-height:1;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0, 0, 0, 0)}.grid.svelte-bny5z.svelte-bny5z{display:inline-grid;grid-template-columns:auto auto}.grid.svelte-bny5z>div.svelte-bny5z{margin-top:10px}.value-name.svelte-bny5z.svelte-bny5z{text-align:right}task-list.svelte-bny5z.svelte-bny5z{display:inline-grid;grid-template-columns:auto auto auto auto auto;width:100%}.button-css.svelte-yar6m3{background-color:black;color:white;font-size:28px;font-family:"DOS", monospace;line-height:1;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0, 0, 0, 0);border:0;padding:5px 10px;display:inline-block;max-width:100%}.button-css.svelte-yar6m3:hover{background:rgb(255, 255, 255);color:#000000}.input-text-css.svelte-4h7oz2{display:inline-block;color:#000;font-size:28px;font-family:"DOS", monospace;line-height:1;box-sizing:border-box;margin:0;border:0;border-bottom:4px solid #000;padding:0 5px 0 5px;box-shadow:none;border-radius:0;-moz-appearance:none;-webkit-appearance:none;appearance:none;background-color:#ffa21c;height:32px}.input-text-css.svelte-4h7oz2:focus-visible,.input-text-css.svelte-4h7oz2:hover{outline:0;background-color:white}@keyframes svelte-1471rey-spinner-animation{0%{content:"|"}25%{content:"/"}50%{content:"-"}75%{content:"\\"}100%{content:"|"}}spinner.svelte-1471rey::after{display:inline-block;animation:svelte-1471rey-spinner-animation 0.6s linear infinite alternate;content:"|"}.button.svelte-1rqr1h4{box-sizing:border-box;display:inline-block;font-size:28px;font-family:"DOS", monospace;line-height:1;border:0;padding:0 5px 0 5px;box-shadow:none;border-radius:0;display:inline-block;max-width:100%}.black.svelte-1rqr1h4{color:white;background-color:black;border-bottom:4px solid #000}.black.svelte-1rqr1h4:hover{background:#fff;color:#000}.normal.svelte-1rqr1h4{color:#000;background-color:#ffa21c;border-bottom:4px solid #ffa21c}.normal.svelte-1rqr1h4:hover{background:#000;color:#fff}select.svelte-1rf61qb.svelte-1rf61qb{display:inline-block;color:#000;font-size:28px;font-family:"DOS", monospace;line-height:1;box-sizing:border-box;margin:0;border:0;border-bottom:4px solid #000;padding:0 5px 0 5px;box-shadow:none;border-radius:0;-moz-appearance:none;-webkit-appearance:none;appearance:none;background-color:#ffa21c}select.svelte-1rf61qb.svelte-1rf61qb::-ms-expand{display:none}select.svelte-1rf61qb.svelte-1rf61qb:hover{background:rgb(255, 255, 255);color:#000000}select.svelte-1rf61qb.svelte-1rf61qb:focus{box-shadow:none;outline:none;background:rgb(255, 255, 255);color:#000000}select.svelte-1rf61qb option.svelte-1rf61qb{font-weight:normal}popup-wrapper.svelte-1ufadaz{background-color:rgba(0, 0, 0, 0.863);width:100%;height:100%;display:table;table-layout:fixed;z-index:999;overflow:auto;position:fixed;top:0;left:0;right:0;bottom:0}popup-body.svelte-1ufadaz{margin:auto;display:table-cell;text-align:center;vertical-align:middle;width:100%}popup-content.svelte-1ufadaz{background-color:#ffa21c;display:inline-block;outline:none;position:relative;text-align:initial;max-width:100vw}popup-border.svelte-1ufadaz{display:block;border:4px dashed #000;margin:10px;padding:10px}popup-close.svelte-1ufadaz{background-color:#000;display:inline-block;color:#ffa21c;position:absolute;width:24px;right:0px;top:0px;text-align:center}popup-close.svelte-1ufadaz:hover{background-color:#fff;color:#000}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@
let server = "";
if (development_mode) {
server = "http://192.168.31.81";
server = "http://172.30.1.84";
}
async function api_post(api, data) {
@ -36,6 +36,7 @@
let popup_message_text;
let mode_select;
let usb_mode_select;
let ap_ssid_input;
let ap_pass_input;
let sta_ssid_input;
@ -53,6 +54,7 @@
await api_post(server + "/api/v1/wifi/set_credentials", {
wifi_mode: mode_select.get_value(),
usb_mode: usb_mode_select.get_value(),
ap_ssid: ap_ssid_input.get_value(),
ap_pass: ap_pass_input.get_value(),
sta_ssid: sta_ssid_input.get_value(),
@ -139,16 +141,22 @@
{#await api_get(server + "/api/v1/wifi/get_credentials")}
<div class="value-name">Mode:</div>
<div><Spinner /></div>
<div class="value-name">STA</div>
<div>(join another network)</div>
<div class="value-name">SSID:</div>
<div><Spinner /></div>
<div class="value-name">Pass:</div>
<div><Spinner /></div>
<div class="value-name">AP</div>
<div>(own access point)</div>
<div class="value-name">SSID:</div>
<div><Spinner /></div>
<div class="value-name">Pass:</div>
<div><Spinner /></div>
<div class="value-name">Hostname:</div>
<div><Spinner /></div>
<div class="value-name">USB mode:</div>
<div><Spinner /></div>
{:then json}
<div class="value-name">Mode:</div>
<div>
@ -157,6 +165,7 @@
items={[
{ text: "STA (join another network)", value: "STA" },
{ text: "AP (own access point)", value: "AP" },
{ text: "Disabled (do not use WiFi)", value: "Disabled" },
]}
value={json.wifi_mode}
/>
@ -193,6 +202,18 @@
<div>
<Input value={json.hostname} bind:this={hostname_input} />
</div>
<div class="value-name">USB mode:</div>
<div>
<Select
bind:this={usb_mode_select}
items={[
{ text: "BlackMagicProbe", value: "BM" },
{ text: "DapLink", value: "DAP" },
]}
value={json.usb_mode}
/>
</div>
{:catch error}
<error>{error.message}</error>
{/await}

View File

@ -33,10 +33,13 @@ void cli_config_get(Cli* cli, mstring_t* args) {
nvs_config_get_wifi_mode(&wifi_mode);
switch(wifi_mode) {
case WiFiModeAP:
mstring_set(value, "AP");
mstring_set(value, CFG_WIFI_MODE_AP);
break;
case WiFiModeSTA:
mstring_set(value, "STA");
mstring_set(value, CFG_WIFI_MODE_STA);
break;
case WiFiModeDisabled:
mstring_set(value, CFG_WIFI_MODE_DISABLED);
break;
}
@ -48,9 +51,11 @@ void cli_config_get(Cli* cli, mstring_t* args) {
void cli_config_set_wifi_mode_usage(Cli* cli) {
cli_write_str(cli, "config_set_wifi_mode <AP|STA>");
cli_write_eol(cli);
cli_write_str(cli, " AP (make own WiFi AP)");
cli_write_str(cli, " " CFG_WIFI_MODE_AP " (make own WiFi AP)");
cli_write_eol(cli);
cli_write_str(cli, " STA (connect to WiFi)");
cli_write_str(cli, " " CFG_WIFI_MODE_STA " (connect to WiFi)");
cli_write_eol(cli);
cli_write_str(cli, " " CFG_WIFI_MODE_DISABLED " (disable WiFi)");
cli_write_eol(cli);
}
@ -64,10 +69,12 @@ void cli_config_set_wifi_mode(Cli* cli, mstring_t* args) {
break;
}
if(mstring_cmp_cstr(mode, "AP") == 0) {
if(mstring_cmp_cstr(mode, CFG_WIFI_MODE_AP) == 0) {
wifi_mode = WiFiModeAP;
} else if(mstring_cmp_cstr(mode, "STA") == 0) {
} else if(mstring_cmp_cstr(mode, CFG_WIFI_MODE_STA) == 0) {
wifi_mode = WiFiModeSTA;
} else if(mstring_cmp_cstr(mode, CFG_WIFI_MODE_DISABLED) == 0) {
wifi_mode = WiFiModeDisabled;
} else {
cli_config_set_wifi_mode_usage(cli);
break;

View File

@ -16,6 +16,7 @@
#include <lwip/netdb.h>
#include "led.h"
#include "usb.h"
#include "delay.h"
#include "network-gdb.h"
#include <gdb-glue.h>
@ -136,21 +137,28 @@ static void network_gdb_server_task(void* pvParameters) {
ESP_LOGI(TAG, "Socket accepted ip address: %s", addr_str);
led_set_blue(255);
delay(10);
led_set_blue(0);
// continue only if DAP-Link is not connected
if(!dap_is_connected()) {
led_set_blue(255);
delay(10);
led_set_blue(0);
network_gdb.socket_id = sock;
network_gdb.connected = true;
ESP_LOGI(TAG, "DAP-Link is connected, not accepting connection");
receive_and_send_to_gdb();
network_gdb.socket_id = sock;
network_gdb.connected = true;
network_gdb.connected = false;
network_gdb.socket_id = -1;
receive_and_send_to_gdb();
led_set_blue(255);
delay(10);
led_set_blue(0);
network_gdb.connected = false;
network_gdb.socket_id = -1;
led_set_blue(255);
delay(10);
led_set_blue(0);
} else {
ESP_LOGE(TAG, "DAP-Link is connected, not accepting connection");
}
shutdown(sock, 0);
close(sock);

View File

@ -307,8 +307,10 @@ static esp_err_t wifi_get_credentials_handler(httpd_req_t* req) {
mstring_t* sta_pass = mstring_alloc();
mstring_t* hostname = mstring_alloc();
WiFiMode wifi_mode;
UsbMode usb_mode;
nvs_config_get_wifi_mode(&wifi_mode);
nvs_config_get_usb_mode(&usb_mode);
nvs_config_get_ap_ssid(ap_ssid);
nvs_config_get_ap_pass(ap_pass);
nvs_config_get_sta_ssid(sta_ssid);
@ -328,6 +330,18 @@ static esp_err_t wifi_get_credentials_handler(httpd_req_t* req) {
case WiFiModeSTA:
cJSON_AddStringToObject(root, "wifi_mode", CFG_WIFI_MODE_STA);
break;
case WiFiModeDisabled:
cJSON_AddStringToObject(root, "wifi_mode", CFG_WIFI_MODE_DISABLED);
break;
}
switch(usb_mode) {
case UsbModeBM:
cJSON_AddStringToObject(root, "usb_mode", CFG_USB_MODE_BM);
break;
case UsbModeDAP:
cJSON_AddStringToObject(root, "usb_mode", CFG_USB_MODE_DAP);
break;
}
const char* json_text = cJSON_Print(root);
@ -352,6 +366,7 @@ static esp_err_t wifi_set_credentials_handler(httpd_req_t* req) {
mstring_t* sta_ssid = mstring_alloc();
mstring_t* sta_pass = mstring_alloc();
mstring_t* wifi_mode = mstring_alloc();
mstring_t* usb_mode = mstring_alloc();
mstring_t* hostname = mstring_alloc();
const char* error_text = JSON_ERROR("unknown error");
int received = 0;
@ -413,6 +428,14 @@ static esp_err_t wifi_set_credentials_handler(httpd_req_t* req) {
goto err_fail;
}
if(cJSON_GetObjectItem(root, "usb_mode") != NULL) {
mstring_set(usb_mode, cJSON_GetObjectItem(root, "usb_mode")->valuestring);
} else {
cJSON_Delete(root);
error_text = JSON_ERROR("request dont have [usb_mode] field");
goto err_fail;
}
if(cJSON_GetObjectItem(root, "hostname") != NULL) {
mstring_set(hostname, cJSON_GetObjectItem(root, "hostname")->valuestring);
} else {
@ -423,10 +446,16 @@ static esp_err_t wifi_set_credentials_handler(httpd_req_t* req) {
cJSON_Delete(root);
if(strcmp(mstring_get_cstr(wifi_mode), CFG_WIFI_MODE_AP) != 0 &&
strcmp(mstring_get_cstr(wifi_mode), CFG_WIFI_MODE_STA) != 0) {
strcmp(mstring_get_cstr(wifi_mode), CFG_WIFI_MODE_STA) != 0 &&
strcmp(mstring_get_cstr(wifi_mode), CFG_WIFI_MODE_DISABLED) != 0) {
error_text = JSON_ERROR("invalid value in [wifi_mode]");
goto err_fail;
}
if(strcmp(mstring_get_cstr(usb_mode), CFG_USB_MODE_BM) != 0 &&
strcmp(mstring_get_cstr(usb_mode), CFG_USB_MODE_DAP) != 0) {
error_text = JSON_ERROR("invalid value in [usb_mode]");
goto err_fail;
}
if(nvs_config_set_ap_ssid(ap_ssid) != ESP_OK) {
error_text = JSON_ERROR("invalid value in [ap_ssid]");
@ -447,12 +476,29 @@ static esp_err_t wifi_set_credentials_handler(httpd_req_t* req) {
if(strcmp(mstring_get_cstr(wifi_mode), CFG_WIFI_MODE_AP) == 0) {
if(nvs_config_set_wifi_mode(WiFiModeAP) != ESP_OK) {
error_text = JSON_ERROR("invalid value in [sta_pass]");
error_text = JSON_ERROR("cannot set [wifi_mode]");
goto err_fail;
}
} else if(strcmp(mstring_get_cstr(wifi_mode), CFG_WIFI_MODE_DISABLED) == 0) {
if(nvs_config_set_wifi_mode(WiFiModeDisabled) != ESP_OK) {
error_text = JSON_ERROR("cannot set [wifi_mode]");
goto err_fail;
}
} else {
if(nvs_config_set_wifi_mode(WiFiModeSTA) != ESP_OK) {
error_text = JSON_ERROR("invalid value in [sta_pass]");
error_text = JSON_ERROR("cannot set [wifi_mode]");
goto err_fail;
}
}
if(strcmp(mstring_get_cstr(usb_mode), CFG_USB_MODE_DAP) == 0) {
if(nvs_config_set_usb_mode(UsbModeDAP) != ESP_OK) {
error_text = JSON_ERROR("cannot set [usb_mode]");
goto err_fail;
}
} else {
if(nvs_config_set_usb_mode(UsbModeBM) != ESP_OK) {
error_text = JSON_ERROR("cannot set [usb_mode]");
goto err_fail;
}
}
@ -469,6 +515,7 @@ static esp_err_t wifi_set_credentials_handler(httpd_req_t* req) {
mstring_free(sta_ssid);
mstring_free(sta_pass);
mstring_free(wifi_mode);
mstring_free(usb_mode);
mstring_free(hostname);
return ESP_OK;

View File

@ -201,6 +201,8 @@ WiFiMode network_init(void) {
nvs_config_get_sta_pass(pass);
network_connect_ap(ssid, pass);
break;
case WiFiModeDisabled:
break;
}
mstring_free(ssid);

View File

@ -9,6 +9,8 @@
#define WIFI_STA_PASS_KEY "wifi_sta_pass"
#define WIFI_HOSTNAME "wifi_hostname"
#define USB_MODE_KEY "usb_mode"
#define ESP_WIFI_DEFAULT_SSID "blackmagic"
#define ESP_WIFI_DEFAULT_PASS "iamwitcher"
#define ESP_WIFI_DEFAULT_HOSTNAME "blackmagic"
@ -23,6 +25,9 @@ esp_err_t nvs_config_set_wifi_mode(WiFiMode value) {
case WiFiModeSTA:
mstring_set(mode, CFG_WIFI_MODE_STA);
break;
case WiFiModeDisabled:
mstring_set(mode, CFG_WIFI_MODE_DISABLED);
break;
}
esp_err_t err = nvs_save_string(WIFI_MODE_KEY, mode);
@ -31,6 +36,24 @@ esp_err_t nvs_config_set_wifi_mode(WiFiMode value) {
return err;
}
esp_err_t nvs_config_set_usb_mode(UsbMode value) {
mstring_t* mode = mstring_alloc();
switch(value) {
case UsbModeBM:
mstring_set(mode, CFG_USB_MODE_BM);
break;
case UsbModeDAP:
mstring_set(mode, CFG_USB_MODE_DAP);
break;
}
esp_err_t err = nvs_save_string(USB_MODE_KEY, mode);
mstring_free(mode);
return err;
}
esp_err_t nvs_config_set_ap_ssid(const mstring_t* ssid) {
esp_err_t err = ESP_FAIL;
@ -87,6 +110,8 @@ esp_err_t nvs_config_get_wifi_mode(WiFiMode* value) {
if(err == ESP_OK && mstring_cmp_cstr(mode, CFG_WIFI_MODE_STA) == 0) {
*value = WiFiModeSTA;
} else if(err == ESP_OK && mstring_cmp_cstr(mode, CFG_WIFI_MODE_DISABLED) == 0) {
*value = WiFiModeDisabled;
} else {
// AP mode by default
*value = WiFiModeAP;
@ -96,6 +121,21 @@ esp_err_t nvs_config_get_wifi_mode(WiFiMode* value) {
return err;
}
esp_err_t nvs_config_get_usb_mode(UsbMode* value) {
mstring_t* mode = mstring_alloc();
esp_err_t err = nvs_load_string(USB_MODE_KEY, mode);
if(err == ESP_OK && mstring_cmp_cstr(mode, CFG_USB_MODE_DAP) == 0) {
*value = UsbModeDAP;
} else {
// USB mode by default
*value = UsbModeBM;
}
mstring_free(mode);
return err;
}
esp_err_t nvs_config_get_ap_ssid(mstring_t* ssid) {
esp_err_t err = nvs_load_string(WIFI_AP_SSID_KEY, ssid);

View File

@ -13,8 +13,9 @@
#define CFG_WIFI_MODE_AP "AP"
#define CFG_WIFI_MODE_STA "STA"
#define CFG_WIFI_MODE_DISABLED "Disabled"
#define CFG_USB_MODE_BLACKMAGIC "BLACKMAGIC"
#define CFG_USB_MODE_BM "BM"
#define CFG_USB_MODE_DAP "DAP"
typedef enum {
@ -25,9 +26,11 @@ typedef enum {
typedef enum {
WiFiModeAP, // host of a WiFi network
WiFiModeSTA, // connected to existing WiFi AP
WiFiModeDisabled, // disabled
} WiFiMode;
esp_err_t nvs_config_set_wifi_mode(WiFiMode value);
esp_err_t nvs_config_set_usb_mode(UsbMode value);
esp_err_t nvs_config_set_ap_ssid(const mstring_t* ssid);
esp_err_t nvs_config_set_ap_pass(const mstring_t* pass);
esp_err_t nvs_config_set_sta_ssid(const mstring_t* ssid);
@ -35,6 +38,7 @@ esp_err_t nvs_config_set_sta_pass(const mstring_t* pass);
esp_err_t nvs_config_set_hostname(const mstring_t* hostname);
esp_err_t nvs_config_get_wifi_mode(WiFiMode* value);
esp_err_t nvs_config_get_usb_mode(UsbMode* value);
esp_err_t nvs_config_get_ap_ssid(mstring_t* ssid);
esp_err_t nvs_config_get_ap_pass(mstring_t* pass);
esp_err_t nvs_config_get_sta_ssid(mstring_t* ssid);

View File

@ -117,8 +117,10 @@ static void usb_from_connected(void* context) {
#include "dap.h"
#include "dap_config.h"
#include "network-gdb.h"
TaskHandle_t dap_task_handle;
bool dap_link_connected = false;
static void dap_rx_callback(void* context) {
xTaskNotify(dap_task_handle, DAP_RECEIVE_FLAG, eSetBits);
@ -127,11 +129,17 @@ static void dap_rx_callback(void* context) {
void dap_callback_connect(void) {
ESP_LOGI(DAP_TAG, "connected");
led_set(0, 0, 0);
dap_link_connected = true;
}
void dap_callback_disconnect(void) {
ESP_LOGI(DAP_TAG, "disconnected");
led_set(255, 0, 0);
dap_link_connected = false;
}
bool dap_is_connected(void) {
return dap_link_connected;
}
static void dap_task(void* arg) {
@ -144,23 +152,29 @@ static void dap_task(void* arg) {
BaseType_t xResult = xTaskNotifyWait(pdFALSE, ULONG_MAX, &notified_value, portMAX_DELAY);
if(xResult == pdPASS) {
if((notified_value & DAP_RECEIVE_FLAG) != 0) {
uint8_t rx_data[DAP_CONFIG_PACKET_SIZE];
uint8_t tx_data[DAP_CONFIG_PACKET_SIZE];
memset(tx_data, 0, DAP_CONFIG_PACKET_SIZE);
memset(rx_data, 0, DAP_CONFIG_PACKET_SIZE);
// continue only if network-gdb is not connected
if(!network_gdb_connected()) {
if((notified_value & DAP_RECEIVE_FLAG) != 0) {
uint8_t rx_data[DAP_CONFIG_PACKET_SIZE];
uint8_t tx_data[DAP_CONFIG_PACKET_SIZE];
memset(tx_data, 0, DAP_CONFIG_PACKET_SIZE);
memset(rx_data, 0, DAP_CONFIG_PACKET_SIZE);
if(counter % 512 == 0) {
led_set_blue(255);
} else if(counter % 512 == 256) {
led_set_blue(0);
if(counter % 512 == 0) {
led_set_blue(255);
} else if(counter % 512 == 256) {
led_set_blue(0);
}
size_t rx_size = usb_glue_dap_receive(rx_data, sizeof(rx_data));
size_t tx_size =
dap_process_request(rx_data, rx_size, tx_data, sizeof(tx_data));
usb_glue_dap_send(tx_data, tx_size, true);
counter++;
}
size_t rx_size = usb_glue_dap_receive(rx_data, sizeof(rx_data));
size_t tx_size = dap_process_request(rx_data, rx_size, tx_data, sizeof(tx_data));
usb_glue_dap_send(tx_data, tx_size, true);
counter++;
} else {
ESP_LOGE(TAG, "GDB is connected, DAP is disabled");
}
}
}
@ -170,7 +184,7 @@ static void usb_dap_init() {
ESP_LOGI(DAP_TAG, "init");
xTaskCreate(
dap_task,
"DAP",
"dap_thread",
CONFIG_DAP_TASK_STACK_SIZE,
NULL,
CONFIG_DAP_TASK_PRIORITY,
@ -182,25 +196,22 @@ void usb_init(void) {
ESP_LOGI(TAG, "init");
// TODO get from config
UsbMode usb_mode = UsbModeDAP;
UsbMode usb_mode = UsbModeBM;
nvs_config_get_usb_mode(&usb_mode);
usb_glue_set_connected_callback(usb_to_connected, NULL);
usb_glue_set_disconnected_callback(usb_from_connected, NULL);
usb_glue_cdc_set_line_coding_callback(usb_set_line_coding_callback, NULL);
usb_glue_cdc_set_line_state_callback(usb_line_state_cb, NULL);
usb_glue_cdc_set_receive_callback(usb_uart_rx_callback, NULL);
if(usb_mode == UsbModeBM) {
usb_glue_set_connected_callback(usb_to_connected, NULL);
usb_glue_set_disconnected_callback(usb_from_connected, NULL);
usb_glue_cdc_set_line_coding_callback(usb_set_line_coding_callback, NULL);
usb_glue_cdc_set_line_state_callback(usb_line_state_cb, NULL);
usb_glue_cdc_set_receive_callback(usb_uart_rx_callback, NULL);
usb_glue_gdb_set_receive_callback(usb_gdb_rx_callback, NULL);
usb_state.connected = false;
usb_uart_init();
usb_glue_init(USBDeviceTypeDualCDC);
} else {
usb_glue_set_connected_callback(usb_to_connected, NULL);
usb_glue_set_disconnected_callback(usb_from_connected, NULL);
usb_glue_cdc_set_line_coding_callback(usb_set_line_coding_callback, NULL);
usb_glue_cdc_set_line_state_callback(usb_line_state_cb, NULL);
usb_glue_cdc_set_receive_callback(usb_uart_rx_callback, NULL);
usb_glue_dap_set_receive_callback(dap_rx_callback, NULL);
usb_state.connected = false;

View File

@ -7,4 +7,6 @@ void usb_init(void);
void usb_gdb_tx_char(uint8_t c, bool flush);
void usb_uart_tx_char(uint8_t c, bool flush);
void usb_uart_tx_char(uint8_t c, bool flush);
bool dap_is_connected(void);