Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SRCS
"./BitForgeHal/src/adc.c"
"./BitForgeHal/src/i2c_bitforge.c"
"main.c"
"setup_ble.c"
"./NvsManager/src/nvs_config.c"
"./HMI/src/input.c"
"system.c"
Expand Down Expand Up @@ -61,6 +62,7 @@ PRIV_REQUIRES
"esp_driver_i2c"
"esp-tls"
"tcp_transport"
"bt"

EMBED_FILES
"http_server/recovery_page.html"
Expand Down
15 changes: 15 additions & 0 deletions main/NvsManager/src/nvs_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ void nvs_config_set_string(const char * key, const char * value)
err = nvs_set_str(handle, key, value);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Could not write nvs key: %s, value: %s", key, value);
} else {
err = nvs_commit(handle);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Could not commit nvs key: %s", key);
}
}

nvs_close(handle);
Expand Down Expand Up @@ -93,6 +98,11 @@ void nvs_config_set_u16(const char * key, const uint16_t value)
err = nvs_set_u16(handle, key, value);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Could not write nvs key: %s, value: %u", key, value);
} else {
err = nvs_commit(handle);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Could not commit nvs key: %s", key);
}
}

nvs_close(handle);
Expand Down Expand Up @@ -133,6 +143,11 @@ void nvs_config_set_u64(const char * key, const uint64_t value)
err = nvs_set_u64(handle, key, value);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Could not write nvs key: %s, value: %llu", key, value);
} else {
err = nvs_commit(handle);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Could not commit nvs key: %s", key);
}
}
nvs_close(handle);
}
6 changes: 6 additions & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "nvs_device.h"
#include "self_test.h"
#include "asic.h"
#include "setup_ble.h"

static GlobalState GLOBAL_STATE = {
.extranonce_str = NULL,
Expand Down Expand Up @@ -60,6 +61,7 @@ static void ap_timeout_task(void * pvParameters)
for (int attempt = 1; attempt <= AP_DISABLE_MAX_ATTEMPTS; attempt++) {
esp_err_t err = wifi_softap_off();
if (err == ESP_OK) {
setup_ble_stop();
ESP_LOGI(TAG, "Setup AP disabled; station WiFi remains active");
break;
}
Expand Down Expand Up @@ -143,6 +145,10 @@ void app_main(void)

generate_ssid(GLOBAL_STATE.SYSTEM_MODULE.ap_ssid);

if (GLOBAL_STATE.SYSTEM_MODULE.ap_enabled) {
setup_ble_start(&GLOBAL_STATE);
}
Comment on lines +148 to +150

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

setup_ble_start() return value is discarded.

If BLE init fails (e.g. nimble_port_init error), setup_ble_start returns ESP_FAIL/ESP_ERR_NOT_SUPPORTED but startup proceeds silently. Logging the failure makes setup-mode issues diagnosable in the field.

Proposed fix
     if (GLOBAL_STATE.SYSTEM_MODULE.ap_enabled) {
-        setup_ble_start(&GLOBAL_STATE);
+        esp_err_t ble_err = setup_ble_start(&GLOBAL_STATE);
+        if (ble_err != ESP_OK) {
+            ESP_LOGW(TAG, "Setup BLE not started: %s", esp_err_to_name(ble_err));
+        }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (GLOBAL_STATE.SYSTEM_MODULE.ap_enabled) {
setup_ble_start(&GLOBAL_STATE);
}
if (GLOBAL_STATE.SYSTEM_MODULE.ap_enabled) {
esp_err_t ble_err = setup_ble_start(&GLOBAL_STATE);
if (ble_err != ESP_OK) {
ESP_LOGW(TAG, "Setup BLE not started: %s", esp_err_to_name(ble_err));
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@main/main.c` around lines 148 - 150, The BLE startup path in main() ignores
the return value from setup_ble_start(), so initialization failures are lost and
startup continues silently. Update the ap_enabled branch to check the result of
setup_ble_start(&GLOBAL_STATE), and when it is not ESP_OK, log the failure with
the returned status (for example using ESP_LOGE) so setup-mode issues are
visible in the field. Keep the change localized to the startup flow that calls
setup_ble_start().


SYSTEM_init_peripherals(&GLOBAL_STATE);

xTaskCreate(POWER_MANAGEMENT_task, "power management", 8192, (void *) &GLOBAL_STATE, 10, NULL);
Expand Down
Loading
Loading