Skip to content
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

Esp insights library support #7566

Merged
merged 28 commits into from
Dec 22, 2022
Merged

Conversation

sanketwadekar
Copy link
Contributor

@sanketwadekar sanketwadekar commented Dec 9, 2022


Description of Change

This PR brings library support for ESP Insights in Arduino.

Tests scenarios

I have tested this library on esp32 dev module.

Related links

Depends on other PRs
espressif/esp32-arduino-lib-builder#100
#7567

@sanketwadekar
Copy link
Contributor Author

Tagging @shahpiyushv and @vikramdattu

@VojtechBartoska VojtechBartoska added Type: Feature request Feature request for Arduino ESP32 Area: Libraries Issue is related to Library support. labels Dec 9, 2022
@me-no-dev
Copy link
Member

lib-builder changes are merged in master (and pulled here)

@me-no-dev
Copy link
Member

@sanketwadekar
Copy link
Contributor Author

There are some errors: https://github.com/espressif/arduino-esp32/actions/runs/3662188925/jobs/6191099956#step:5:255

The errors are coming from esp-insights repo. Some changes are required in esp-insights for this pipeline to pass. MR for these changes has been raised.

@me-no-dev
Copy link
Member

The errors are coming from esp-insights repo. Some changes are required in esp-insights for this pipeline to pass. MR for these changes has been raised.

Then this means that even the changes in lib-builder were too early to post. When will that MR get merged and changes available on github?

@sanketwadekar
Copy link
Contributor Author

The MR should get merged in this week.

@me-no-dev
Copy link
Member

@sanketwadekar after a couple of minor fixes, CI is passing. Onto review :)

@@ -0,0 +1,767 @@
############
Copy link
Member

Choose a reason for hiding this comment

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

if (s_reset_count > MAX_CRASHES) {
ESP_DIAG_EVENT(TAG, "[count][%d]", count);
} else {
log_e("[count][%d] [crash_count][%"PRIu32"] [excvaddr][0x0f] Crashing...", count, s_reset_count);
Copy link
Member

Choose a reason for hiding this comment

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

warnings are generated if there is no space between quoted text/defines.

log_e("[count][%d] [crash_count][%" PRIu32 "] [excvaddr][0x0f] Crashing...", count, s_reset_count);

void *p = malloc(size);
if (p) {
memset(p, size, 'A' + (esp_random() % 26));
log_i("Allocated %"PRIu32" bytes", size);
Copy link
Member

Choose a reason for hiding this comment

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

Same note as above

Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSPHRASE);
if(!WiFi.isConnected()) {
Copy link
Member

Choose a reason for hiding this comment

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

same note about how to wait for WiFi connect

platform.txt Outdated
@@ -24,6 +24,9 @@ tools.esp_ota.cmd.windows="{runtime.platform.path}/tools/espota.exe" -r
tools.gen_esp32part.cmd=python3 "{runtime.platform.path}/tools/gen_esp32part.py"
tools.gen_esp32part.cmd.windows="{runtime.platform.path}/tools/gen_esp32part.exe"

tools.gen_insights_pkg.cmd = python3 {runtime.platform.path}/tools/gen_insights_package.py
tools.gen_insights_pkg.cmd.windows = {runtime.platform.path}/tools/gen_insights_package.exe
Copy link
Member

Choose a reason for hiding this comment

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

I suggest you quote and format the commands as the ones above in order to prevent possible path/etc issues.

Copy link
Contributor Author

@sanketwadekar sanketwadekar Dec 21, 2022

Choose a reason for hiding this comment

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

I get errors if I add quotes

/var/folders/0l/c75rh0953fng_6ccdgnm48gr0000gn/T/arduino_build_640628: -c: line 0: unexpected EOF while looking for matching `"'
/var/folders/0l/c75rh0953fng_6ccdgnm48gr0000gn/T/arduino_build_640628: -c: line 1: syntax error: unexpected end of file

Can you please help me out with this?

Also, I need some help to test this on Windows.
Thanks

Copy link
Member

Choose a reason for hiding this comment

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

@SuGlider please help with testing on Windows

@@ -211,10 +214,15 @@ recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-Wl,--Map={build
recipe.objcopy.partitions.bin.pattern={tools.gen_esp32part.cmd} -q "{build.path}/partitions.csv" "{build.path}/{build.project_name}.partitions.bin"

## Create bin
recipe.objcopy.bin.pattern_args=--chip {build.mcu} elf2image --flash_mode "{build.flash_mode}" --flash_freq "{build.flash_freq}" --flash_size "{build.flash_size}" -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf"
recipe.objcopy.bin.pattern_args=--chip {build.mcu} elf2image --flash_mode "{build.flash_mode}" --flash_freq "{build.flash_freq}" --flash_size "{build.flash_size}" --elf-sha256-offset 0xb0 -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf"
Copy link
Member

Choose a reason for hiding this comment

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

--elf-sha256-offset 0xb0 Is this change necessary? What does it do?

Choose a reason for hiding this comment

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

Hi @me-no-dev the sha256 of firmware is needed for debugging by ESP-Insights backend.

esptool.py from ESP-IDF inserts sha256 by default and is implicit. In case of Arduino however this change was not present. Maybe it was not found useful to add this at the point.

https://github.com/espressif/esp-idf/blob/master/components/esptool_py/project_include.cmake#L48

Copy link
Member

Choose a reason for hiding this comment

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

@ivankravets @valeros PTAL. This is needed for elf2bin part

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it will suffice to add a hot fix directly to the PlatformIO build script in this repo until a new version of the core with this feature is released.

@sanketwadekar Please add the following snippet somewhere at the bottom of https://github.com/espressif/arduino-esp32/blob/master/tools/platformio-build.py:

#
#  Adjust the `esptoolpy` command in the `ElfToBin` builder with firmware checksum offset
#

action = deepcopy(env["BUILDERS"]["ElfToBin"].action)
action.cmd_list = env["BUILDERS"]["ElfToBin"].action.cmd_list.replace(
    "-o", "--elf-sha256-offset 0xb0 -o"
)
env["BUILDERS"]["ElfToBin"].action = action

Also, an extra import should be added at the top of the same file:

from copy import deepcopy

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PTAL

platform.txt Outdated
recipe.objcopy.bin.pattern="{tools.esptool_py.path}/{tools.esptool_py.cmd}" {recipe.objcopy.bin.pattern_args}
recipe.objcopy.bin.pattern.linux=python3 "{tools.esptool_py.path}/{tools.esptool_py.cmd}" {recipe.objcopy.bin.pattern_args}

## Create Insights Firmware Package
recipe.hooks.objcopy.postobjcopy.1.pattern_args={build.path} {build.project_name} {build.path}
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't it make more sense to output the zip to the sketch folder instead?

boards.txt Outdated
@@ -672,6 +672,9 @@ esp32.menu.PartitionScheme.fatflash.upload.maximum_size=2097152
esp32.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9.9MB FATFS)
esp32.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB
esp32.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728
esp32.menu.PartitionScheme.insights=Insights
esp32.menu.PartitionScheme.insights.build.partitions=insights
esp32.menu.PartitionScheme.insights.upload.maximum_size=3145728
Copy link
Member

Choose a reason for hiding this comment

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

this should be added to the other dev boards as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PTAL

@@ -0,0 +1,28 @@
// Copyright 2015-2022 Espressif Systems (Shanghai) PTE LTD

Choose a reason for hiding this comment

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

Let's change the license header to SPDX format and attribute year 2022 only.

/*
 * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: Apache-2.0
 */

};

extern DiagnosticsClass Diagnostics;
#endif

Choose a reason for hiding this comment

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

minor: new lines missing at multiple places

@@ -0,0 +1,139 @@
#include "sdkconfig.h"

Choose a reason for hiding this comment

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

Please add license header to all files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PTAL

@@ -4,4 +4,5 @@ otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x300000,
app1, app, ota_1, 0x310000,0x300000,
ffat, data, fat, 0x610000,0x9F0000,
# to create/use ffat, see https://github.com/marcmerlin/esp32_fatfsimage
coredump, data, coredump, , 64K,
# to create/use ffat, see https://github.com/marcmerlin/esp32_fatfsimage
Copy link
Member

Choose a reason for hiding this comment

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

if you do not lower the size of the last partition, coredump will end up outside of the flash chip

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would leaving it blank cause it to automatically take up the rest of the space?

Copy link
Member

Choose a reason for hiding this comment

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

afraid not. You do need to subtract 64K from the size

nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
ota_0, app, ota_0, 0x10000, 0x1E0000,
coredump, data, coredump, , 64K,
Copy link
Member

Choose a reason for hiding this comment

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

we should not need this anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have you tested any Insights examples with other partitions? If it works well, then this can be removed.

Copy link
Member

Choose a reason for hiding this comment

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

I have not tried because look at my previous comment: "if you do not lower the size of the last partition, coredump will end up outside of the flash chip"

@pedrominatel pedrominatel self-requested a review December 21, 2022 14:36
Copy link
Member

@pedrominatel pedrominatel left a comment

Choose a reason for hiding this comment

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

Here are my comments and suggestions, otherwise LGTM.

docs/source/api/insights.rst Outdated Show resolved Hide resolved
docs/source/api/insights.rst Outdated Show resolved Hide resolved
docs/source/api/insights.rst Outdated Show resolved Hide resolved
docs/source/api/insights.rst Outdated Show resolved Hide resolved
docs/source/api/insights.rst Outdated Show resolved Hide resolved
@me-no-dev me-no-dev marked this pull request as ready for review December 21, 2022 18:00
@me-no-dev me-no-dev merged commit 161b167 into espressif:master Dec 22, 2022
@urish
Copy link
Contributor

urish commented Jan 8, 2023

After upgrading Wokwi to arduino-esp32 2.0.6, users started getting the following errors in the serial monitor:

E (10) esp_core_dump_flash: No core dump partition found!
E (10) esp_core_dump_flash: No core dump partition found!

the code still runs successfully. I'm not sure if we should add a core dump partition to the default partition table that Wokwi generates?
The title of this pull request says "Draft:", so is it final or still work-in-progress?

@me-no-dev
Copy link
Member

Hi @urish . I guess github does not remove the string "Draft:" even thou it added it. Anyway, this is already a part of 2.0.6, so please add a 64KB coredump partition to wokwi

@urish
Copy link
Contributor

urish commented Jan 9, 2023

Thanks! Now getting:

E (10) esp_core_dump_flash: Failed to read core dump data size (258)!

Should we also initialize the partition somehow?

@urish
Copy link
Contributor

urish commented Jan 9, 2023

Never mind, it turns out the partition offset was incorrect. Now it works well!

@VojtechBartoska VojtechBartoska changed the title Draft: Esp insights library support Esp insights library support Apr 27, 2023
@Jason2866 Jason2866 mentioned this pull request Dec 30, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Libraries Issue is related to Library support. Type: Feature request Feature request for Arduino ESP32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants