-
Notifications
You must be signed in to change notification settings - Fork 7.8k
feat(hosted): Add OTA and version functionality to esp-hosted #11936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
99e010c
d37b613
6e1c1f9
8911fa6
da8352c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,9 +18,10 @@ | |||||
| #include "esp32-hal-hosted.h" | ||||||
| #include "esp32-hal-log.h" | ||||||
|
|
||||||
| #include "esp_hosted.h" | ||||||
| #include "esp_hosted_transport_config.h" | ||||||
| extern esp_err_t esp_hosted_init(); | ||||||
| extern esp_err_t esp_hosted_deinit(); | ||||||
| // extern esp_err_t esp_hosted_init(); | ||||||
| // extern esp_err_t esp_hosted_deinit(); | ||||||
|
|
||||||
| static bool hosted_initialized = false; | ||||||
| static bool hosted_ble_active = false; | ||||||
|
|
@@ -46,6 +47,104 @@ static sdio_pin_config_t sdio_pin_config = { | |||||
| #endif | ||||||
| }; | ||||||
|
|
||||||
| static esp_hosted_coprocessor_fwver_t slave_version_struct = { | ||||||
| .major1 = 0, | ||||||
| .minor1 = 0, | ||||||
| .patch1 = 0 | ||||||
| }; | ||||||
| static esp_hosted_coprocessor_fwver_t host_version_struct = { | ||||||
| .major1 = ESP_HOSTED_VERSION_MAJOR_1, | ||||||
| .minor1 = ESP_HOSTED_VERSION_MINOR_1, | ||||||
| .patch1 = ESP_HOSTED_VERSION_PATCH_1 | ||||||
| }; | ||||||
|
|
||||||
| void hostedGetHostVersion(uint32_t * major, uint32_t * minor, uint32_t * patch) { | ||||||
| *major = host_version_struct.major1; | ||||||
| *minor = host_version_struct.minor1; | ||||||
| *patch = host_version_struct.patch1; | ||||||
| } | ||||||
|
|
||||||
| void hostedGetSlaveVersion(uint32_t * major, uint32_t * minor, uint32_t * patch) { | ||||||
| *major = slave_version_struct.major1; | ||||||
| *minor = slave_version_struct.minor1; | ||||||
| *patch = slave_version_struct.patch1; | ||||||
| } | ||||||
|
|
||||||
| bool hostedHasUpdate() { | ||||||
| uint32_t host_version = ESP_HOSTED_VERSION_VAL(host_version_struct.major1, host_version_struct.minor1, host_version_struct.patch1); | ||||||
| uint32_t slave_version = ESP_HOSTED_VERSION_VAL(slave_version_struct.major1, slave_version_struct.minor1, slave_version_struct.patch1); | ||||||
|
|
||||||
| esp_err_t ret = esp_hosted_get_coprocessor_fwversion(&slave_version_struct); | ||||||
| if (ret != ESP_OK) { | ||||||
| log_e("Could not get slave firmware version: %s", esp_err_to_name(ret)); | ||||||
lucasssvaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } else { | ||||||
| slave_version = ESP_HOSTED_VERSION_VAL(slave_version_struct.major1, slave_version_struct.minor1, slave_version_struct.patch1); | ||||||
| } | ||||||
|
|
||||||
| log_i("Host firmware version: %" PRIu32 ".%" PRIu32 ".%" PRIu32, host_version_struct.major1, host_version_struct.minor1, host_version_struct.patch1); | ||||||
| log_i("Slave firmware version: %" PRIu32 ".%" PRIu32 ".%" PRIu32, slave_version_struct.major1, slave_version_struct.minor1, slave_version_struct.patch1); | ||||||
|
|
||||||
| // compare major.minor only | ||||||
| // slave_version &= 0xFFFFFF00; | ||||||
| // host_version &= 0xFFFFFF00; | ||||||
|
|
||||||
| if (host_version == slave_version) { | ||||||
| log_i("Versions Match!"); | ||||||
| } else if (host_version > slave_version) { | ||||||
| log_w("Version on Host is NEWER than version on co-processor"); | ||||||
| log_w("Update URL: %s", hostedGetUpdateURL()); | ||||||
| return true; | ||||||
| } else { | ||||||
| log_w("Version on Host is OLDER than version on co-processor"); | ||||||
| } | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| char * hostedGetUpdateURL() { | ||||||
| // https://espressif.github.io/arduino-esp32/hosted/esp32c6-v1.2.3.bin | ||||||
| static char url[92] = {0}; | ||||||
| snprintf(url, 92, "https://espressif.github.io/arduino-esp32/hosted/%s-v%" PRIu32 ".%" PRIu32 ".%" PRIu32 ".bin", | ||||||
| CONFIG_ESP_HOSTED_IDF_SLAVE_TARGET, host_version_struct.major1, host_version_struct.minor1, host_version_struct.patch1); | ||||||
| return url; | ||||||
| } | ||||||
|
|
||||||
| bool hostedBeginUpdate() { | ||||||
| esp_err_t err = esp_hosted_slave_ota_begin(); | ||||||
| if (err != ESP_OK) { | ||||||
| log_e("Failed to begin Update: %s", esp_err_to_name(err)); | ||||||
| } | ||||||
| return err == ESP_OK; | ||||||
| } | ||||||
|
|
||||||
| bool hostedWriteUpdate(uint8_t* buf, uint32_t len) { | ||||||
| esp_err_t err = esp_hosted_slave_ota_write(buf, len); | ||||||
| if (err != ESP_OK) { | ||||||
| log_e("Failed to write Update: %s", esp_err_to_name(err)); | ||||||
| } | ||||||
| return err == ESP_OK; | ||||||
| } | ||||||
|
|
||||||
| bool hostedEndUpdate() { | ||||||
| esp_err_t err = esp_hosted_slave_ota_end(); | ||||||
| if (err != ESP_OK) { | ||||||
| log_e("Failed to end Update: %s", esp_err_to_name(err)); | ||||||
| } | ||||||
| return err == ESP_OK; | ||||||
| } | ||||||
|
|
||||||
| bool hostedActivateUpdate() { | ||||||
| esp_err_t err = esp_hosted_slave_ota_activate(); | ||||||
| if (err != ESP_OK) { | ||||||
| log_e("Failed to activate Update: %s", esp_err_to_name(err)); | ||||||
| } | ||||||
| // else { | ||||||
| // hostedDeinit(); | ||||||
| // delay(1000); | ||||||
| // hostedInit(); | ||||||
| // } | ||||||
| return err == ESP_OK; | ||||||
| } | ||||||
|
|
||||||
| static bool hostedInit() { | ||||||
| if (!hosted_initialized) { | ||||||
| log_i("Initializing ESP-Hosted"); | ||||||
|
|
@@ -69,6 +168,12 @@ static bool hostedInit() { | |||||
| return false; | ||||||
| } | ||||||
| log_i("ESP-Hosted initialized!"); | ||||||
| if (esp_hosted_connect_to_slave() != ESP_OK) { | ||||||
| log_e("Failed to connect to slave"); | ||||||
| return false; | ||||||
| } | ||||||
| hostedHasUpdate(); | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| // Attach pins to PeriMan here | ||||||
|
|
@@ -101,6 +206,19 @@ static bool hostedDeinit() { | |||||
|
|
||||||
| bool hostedInitBLE() { | ||||||
| log_i("Initializing ESP-Hosted for BLE"); | ||||||
| if (!hostedInit()) { | ||||||
| return false; | ||||||
| } | ||||||
| esp_err_t err = esp_hosted_bt_controller_init(); | ||||||
| if (err != ESP_OK) { | ||||||
| log_e("esp_hosted_bt_controller_init failed: %s", esp_err_to_name(err)); | ||||||
| return false; | ||||||
| } | ||||||
| err = esp_hosted_bt_controller_enable(); | ||||||
| if (err != ESP_OK) { | ||||||
| log_e("esp_hosted_bt_controller_enable failed: %s", esp_err_to_name(err)); | ||||||
| return false; | ||||||
| } | ||||||
| hosted_ble_active = true; | ||||||
| return hostedInit(); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? it needs to init here. API has changed BTW
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is already being called in line 209. |
||||||
| } | ||||||
|
|
@@ -113,6 +231,16 @@ bool hostedInitWiFi() { | |||||
|
|
||||||
| bool hostedDeinitBLE() { | ||||||
| log_i("Deinitializing ESP-Hosted for BLE"); | ||||||
| esp_err_t err = esp_hosted_bt_controller_disable(); | ||||||
| if (err != ESP_OK) { | ||||||
| log_e("esp_hosted_bt_controller_disable failed: %s", esp_err_to_name(err)); | ||||||
| return false; | ||||||
| } | ||||||
| err = esp_hosted_bt_controller_deinit(false); | ||||||
| if (err != ESP_OK) { | ||||||
| log_e("esp_hosted_bt_controller_deinit failed: %s", esp_err_to_name(err)); | ||||||
| return false; | ||||||
| } | ||||||
| hosted_ble_active = false; | ||||||
| if (!hosted_wifi_active) { | ||||||
| return hostedDeinit(); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? It needs to build the version and later compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it can't get the version it will expand to 0 and if it can it will be replaced in line 81.