mlonmcu 0.3.0.dev0__3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mlonmcu/__init__.py +26 -0
- mlonmcu/artifact.py +172 -0
- mlonmcu/cli/__init__.py +19 -0
- mlonmcu/cli/build.py +119 -0
- mlonmcu/cli/cleanup.py +75 -0
- mlonmcu/cli/common.py +227 -0
- mlonmcu/cli/compile.py +87 -0
- mlonmcu/cli/env.py +68 -0
- mlonmcu/cli/export.py +93 -0
- mlonmcu/cli/flow.py +67 -0
- mlonmcu/cli/helper/__init__.py +18 -0
- mlonmcu/cli/helper/filter.py +25 -0
- mlonmcu/cli/helper/parse.py +159 -0
- mlonmcu/cli/init.py +130 -0
- mlonmcu/cli/load.py +87 -0
- mlonmcu/cli/main.py +116 -0
- mlonmcu/cli/models.py +48 -0
- mlonmcu/cli/run.py +56 -0
- mlonmcu/cli/setup.py +136 -0
- mlonmcu/cli/tune.py +48 -0
- mlonmcu/config.py +219 -0
- mlonmcu/context/__init__.py +22 -0
- mlonmcu/context/context.py +545 -0
- mlonmcu/context/read_write_filelock.py +327 -0
- mlonmcu/environment/__init__.py +18 -0
- mlonmcu/environment/config.py +214 -0
- mlonmcu/environment/environment.py +501 -0
- mlonmcu/environment/init.py +191 -0
- mlonmcu/environment/list.py +81 -0
- mlonmcu/environment/loader.py +250 -0
- mlonmcu/environment/templates.py +69 -0
- mlonmcu/environment/writer.py +117 -0
- mlonmcu/feature/__init__.py +18 -0
- mlonmcu/feature/feature.py +230 -0
- mlonmcu/feature/features.py +1537 -0
- mlonmcu/feature/type.py +33 -0
- mlonmcu/flow/__init__.py +61 -0
- mlonmcu/flow/backend.py +234 -0
- mlonmcu/flow/framework.py +69 -0
- mlonmcu/flow/tflm/__init__.py +23 -0
- mlonmcu/flow/tflm/backend/__init__.py +23 -0
- mlonmcu/flow/tflm/backend/backend.py +47 -0
- mlonmcu/flow/tflm/backend/tflmc.py +129 -0
- mlonmcu/flow/tflm/backend/tflmi.py +385 -0
- mlonmcu/flow/tflm/framework.py +81 -0
- mlonmcu/flow/tvm/__init__.py +23 -0
- mlonmcu/flow/tvm/backend/__init__.py +26 -0
- mlonmcu/flow/tvm/backend/backend.py +282 -0
- mlonmcu/flow/tvm/backend/model_info.py +307 -0
- mlonmcu/flow/tvm/backend/python_utils.py +36 -0
- mlonmcu/flow/tvm/backend/tuner.py +41 -0
- mlonmcu/flow/tvm/backend/tvmaot.py +162 -0
- mlonmcu/flow/tvm/backend/tvmaotplus.py +51 -0
- mlonmcu/flow/tvm/backend/tvmc_utils.py +172 -0
- mlonmcu/flow/tvm/backend/tvmcg.py +102 -0
- mlonmcu/flow/tvm/backend/tvmllvm.py +106 -0
- mlonmcu/flow/tvm/backend/tvmrt.py +151 -0
- mlonmcu/flow/tvm/backend/wrapper.py +645 -0
- mlonmcu/flow/tvm/framework.py +96 -0
- mlonmcu/logging.py +79 -0
- mlonmcu/mlonmcu.py +19 -0
- mlonmcu/models/__init__.py +31 -0
- mlonmcu/models/convert_data.py +107 -0
- mlonmcu/models/frontend.py +571 -0
- mlonmcu/models/group.py +29 -0
- mlonmcu/models/lookup.py +345 -0
- mlonmcu/models/metadata.py +133 -0
- mlonmcu/models/model.py +104 -0
- mlonmcu/models/options.py +64 -0
- mlonmcu/models/utils.py +136 -0
- mlonmcu/platform/__init__.py +27 -0
- mlonmcu/platform/_platform.py +46 -0
- mlonmcu/platform/espidf/__init__.py +25 -0
- mlonmcu/platform/espidf/espidf.py +489 -0
- mlonmcu/platform/espidf/espidf_target.py +257 -0
- mlonmcu/platform/lookup.py +126 -0
- mlonmcu/platform/microtvm/__init__.py +25 -0
- mlonmcu/platform/microtvm/microtvm.py +580 -0
- mlonmcu/platform/microtvm/microtvm_arduino_target.py +68 -0
- mlonmcu/platform/microtvm/microtvm_backend.py +64 -0
- mlonmcu/platform/microtvm/microtvm_espidf_target.py +94 -0
- mlonmcu/platform/microtvm/microtvm_etissvp_target.py +98 -0
- mlonmcu/platform/microtvm/microtvm_host_target.py +46 -0
- mlonmcu/platform/microtvm/microtvm_spike_target.py +230 -0
- mlonmcu/platform/microtvm/microtvm_target.py +189 -0
- mlonmcu/platform/microtvm/microtvm_template_target.py +55 -0
- mlonmcu/platform/microtvm/microtvm_zephyr_target.py +91 -0
- mlonmcu/platform/mlif/__init__.py +25 -0
- mlonmcu/platform/mlif/mlif.py +300 -0
- mlonmcu/platform/mlif/mlif_target.py +86 -0
- mlonmcu/platform/platform.py +244 -0
- mlonmcu/platform/tvm/__init__.py +25 -0
- mlonmcu/platform/tvm/tvm.py +429 -0
- mlonmcu/platform/tvm/tvm_backend.py +57 -0
- mlonmcu/platform/tvm/tvm_target.py +165 -0
- mlonmcu/platform/zephyr/__init__.py +25 -0
- mlonmcu/platform/zephyr/zephyr.py +450 -0
- mlonmcu/platform/zephyr/zephyr_target.py +110 -0
- mlonmcu/plugins.py +26 -0
- mlonmcu/report.py +99 -0
- mlonmcu/session/__init__.py +18 -0
- mlonmcu/session/postprocess/__init__.py +43 -0
- mlonmcu/session/postprocess/postprocess.py +62 -0
- mlonmcu/session/postprocess/postprocesses.py +487 -0
- mlonmcu/session/run.py +1008 -0
- mlonmcu/session/session.py +373 -0
- mlonmcu/setup/__init__.py +18 -0
- mlonmcu/setup/cache.py +147 -0
- mlonmcu/setup/gen_requirements.py +619 -0
- mlonmcu/setup/setup.py +285 -0
- mlonmcu/setup/task.py +380 -0
- mlonmcu/setup/tasks/__init__.py +40 -0
- mlonmcu/setup/tasks/arm_gcc.py +58 -0
- mlonmcu/setup/tasks/cmsisnn.py +151 -0
- mlonmcu/setup/tasks/common.py +36 -0
- mlonmcu/setup/tasks/corstone300.py +64 -0
- mlonmcu/setup/tasks/espidf.py +87 -0
- mlonmcu/setup/tasks/etiss.py +147 -0
- mlonmcu/setup/tasks/llvm.py +67 -0
- mlonmcu/setup/tasks/mlif.py +49 -0
- mlonmcu/setup/tasks/muriscvnn.py +166 -0
- mlonmcu/setup/tasks/pulp.py +192 -0
- mlonmcu/setup/tasks/riscv_gcc.py +146 -0
- mlonmcu/setup/tasks/spike.py +190 -0
- mlonmcu/setup/tasks/tf.py +92 -0
- mlonmcu/setup/tasks/tflite.py +59 -0
- mlonmcu/setup/tasks/tflmc.py +141 -0
- mlonmcu/setup/tasks/tvm.py +172 -0
- mlonmcu/setup/tasks/utvmcg.py +96 -0
- mlonmcu/setup/tasks/zephyr.py +119 -0
- mlonmcu/setup/utils.py +374 -0
- mlonmcu/target/__init__.py +37 -0
- mlonmcu/target/_target.py +41 -0
- mlonmcu/target/arm/__init__.py +3 -0
- mlonmcu/target/arm/corstone300.py +235 -0
- mlonmcu/target/arm/util.py +109 -0
- mlonmcu/target/common.py +194 -0
- mlonmcu/target/elf.py +256 -0
- mlonmcu/target/host_x86.py +84 -0
- mlonmcu/target/metrics.py +75 -0
- mlonmcu/target/riscv/__init__.py +7 -0
- mlonmcu/target/riscv/etiss_pulpino.py +462 -0
- mlonmcu/target/riscv/gvsoc_pulp.py +215 -0
- mlonmcu/target/riscv/ovpsim.py +301 -0
- mlonmcu/target/riscv/riscv.py +185 -0
- mlonmcu/target/riscv/riscv_qemu.py +166 -0
- mlonmcu/target/riscv/spike.py +243 -0
- mlonmcu/target/riscv/util.py +134 -0
- mlonmcu/target/target.py +200 -0
- mlonmcu/utils.py +49 -0
- mlonmcu/version.py +21 -0
- mlonmcu-0.3.0.dev0.dist-info/LICENSE +202 -0
- mlonmcu-0.3.0.dev0.dist-info/METADATA +343 -0
- mlonmcu-0.3.0.dev0.dist-info/NOTICE +8 -0
- mlonmcu-0.3.0.dev0.dist-info/RECORD +376 -0
- mlonmcu-0.3.0.dev0.dist-info/WHEEL +5 -0
- mlonmcu-0.3.0.dev0.dist-info/entry_points.txt +3 -0
- mlonmcu-0.3.0.dev0.dist-info/top_level.txt +1 -0
- resources/frameworks/tvm/crt_config/README.md +7 -0
- resources/frameworks/tvm/crt_config/crt_config.h +53 -0
- resources/frameworks/tvm/tuning_records/riscv_cpu_v0.01.log.best +46 -0
- resources/patches/fix_esp32c3_march.patch +20 -0
- resources/patches/pulp_freertos_support.patch +55 -0
- resources/platforms/espidf/micro_speech_esp32devboard/CMakeLists.txt +29 -0
- resources/platforms/espidf/micro_speech_esp32devboard/README.md +70 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/CMakeLists.txt +78 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/Kconfig +76 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/default_data.c +26 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/default_model_support/process_input.c +35 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/default_model_support/process_output.c +45 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/include/exit.h +26 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/include/ml_interface.h +70 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/include/printing.h +31 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/ml_interface.c +74 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/ml_interface_tflm.cc +64 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/ml_interface_tvm.c +53 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/tflite-lib/CMakeLists.txt +140 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/tflite-lib/Kconfig +8 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/tvm-lib/CMakeLists.txt +66 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/tvm-lib/Kconfig +7 -0
- resources/platforms/espidf/micro_speech_esp32devboard/example_test.py +38 -0
- resources/platforms/espidf/micro_speech_esp32devboard/info.txt +9 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/CMakeLists.txt +58 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/audio_provider.cc +193 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/audio_provider.h +49 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/command_responder.cc +53 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/command_responder.h +35 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/feature_provider.cc +132 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/feature_provider.cc.orig +145 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/feature_provider.h +55 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/COPYING +11 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/_kiss_fft_guts.h +168 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/kiss_fft.c +408 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/kiss_fft.h +124 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/tools/kiss_fftr.c +159 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/tools/kiss_fftr.h +46 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/main.cc +63 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/main_functions.cc +204 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/main_functions.h +37 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/micro_features_generator.cc +121 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/micro_features_generator.h +38 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/micro_model_settings.cc +23 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/micro_model_settings.h +43 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/bits.h +102 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft.cc +52 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft.h +50 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft_util.cc +69 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft_util.h +34 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank.c +134 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank.h +63 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank_util.c +220 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank_util.h +50 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend.c +72 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend.h +64 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend_util.c +85 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend_util.h +52 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/kiss_fft_common.h +48 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/kiss_fft_int16.cc +8 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/kiss_fft_int16.h +34 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_lut.c +30 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_lut.h +40 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale.c +83 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale.h +39 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale_util.c +27 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale_util.h +45 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction.c +51 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction.h +46 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction_util.c +45 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction_util.h +50 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control.c +56 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control.h +47 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control_util.c +92 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control_util.h +57 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window.c +70 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window.h +49 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window_util.c +73 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window_util.h +45 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/pins.c +14 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/pins.h +30 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/recognize_commands.cc +150 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/recognize_commands.h +173 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/ringbuf.c +333 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/ringbuf.h +74 -0
- resources/platforms/espidf/micro_speech_esp32devboard/sdkconfig.defaults +36 -0
- resources/platforms/espidf/project/CMakeLists.txt +29 -0
- resources/platforms/espidf/project/README.md +70 -0
- resources/platforms/espidf/project/components/mlif/CMakeLists.txt +77 -0
- resources/platforms/espidf/project/components/mlif/Kconfig +76 -0
- resources/platforms/espidf/project/components/mlif/default_data.c +26 -0
- resources/platforms/espidf/project/components/mlif/default_model_support/process_input.c +35 -0
- resources/platforms/espidf/project/components/mlif/default_model_support/process_output.c +45 -0
- resources/platforms/espidf/project/components/mlif/include/exit.h +26 -0
- resources/platforms/espidf/project/components/mlif/include/ml_interface.h +60 -0
- resources/platforms/espidf/project/components/mlif/include/printing.h +31 -0
- resources/platforms/espidf/project/components/mlif/ml_interface.c +54 -0
- resources/platforms/espidf/project/components/mlif/ml_interface_tflm.cc +40 -0
- resources/platforms/espidf/project/components/mlif/ml_interface_tvm.c +40 -0
- resources/platforms/espidf/project/components/tflite-lib/CMakeLists.txt +142 -0
- resources/platforms/espidf/project/components/tflite-lib/Kconfig +8 -0
- resources/platforms/espidf/project/components/tvm-lib/CMakeLists.txt +66 -0
- resources/platforms/espidf/project/components/tvm-lib/Kconfig +7 -0
- resources/platforms/espidf/project/example_test.py +38 -0
- resources/platforms/espidf/project/main/CMakeLists.txt +25 -0
- resources/platforms/espidf/project/main/main.c +57 -0
- resources/platforms/espidf/project/sdkconfig.defaults +26 -0
- resources/platforms/zephyr/project/CMakeLists.txt +22 -0
- resources/platforms/zephyr/project/Kconfig +101 -0
- resources/platforms/zephyr/project/README.rst +33 -0
- resources/platforms/zephyr/project/cmake/AddAllSubdirs.cmake +21 -0
- resources/platforms/zephyr/project/cmake/ChooseTarget.cmake +22 -0
- resources/platforms/zephyr/project/cmake/LinkTFLite.cmake +223 -0
- resources/platforms/zephyr/project/cmake/LinkTVM.cmake +68 -0
- resources/platforms/zephyr/project/cmake/LookupClang.cmake +41 -0
- resources/platforms/zephyr/project/cmake/backends/tflmc.cmake +5 -0
- resources/platforms/zephyr/project/cmake/backends/tflmi.cmake +5 -0
- resources/platforms/zephyr/project/cmake/backends/tvmaot.cmake +10 -0
- resources/platforms/zephyr/project/cmake/backends/tvmaotplus.cmake +10 -0
- resources/platforms/zephyr/project/cmake/backends/tvmcg.cmake +10 -0
- resources/platforms/zephyr/project/cmake/backends/tvmllvm.cmake +8 -0
- resources/platforms/zephyr/project/cmake/backends/tvmrt.cmake +8 -0
- resources/platforms/zephyr/project/cmake/extras.cmake +9 -0
- resources/platforms/zephyr/project/cmake/features/auto_vectorize_gcc.cmake +65 -0
- resources/platforms/zephyr/project/cmake/features/auto_vectorize_llvm.cmake +20 -0
- resources/platforms/zephyr/project/cmake/features/cmsisnn.cmake +86 -0
- resources/platforms/zephyr/project/cmake/features/muriscvnn.cmake +87 -0
- resources/platforms/zephyr/project/cmake/frameworks/tflm.cmake +1 -0
- resources/platforms/zephyr/project/cmake/frameworks/tflm_mlif.cmake +8 -0
- resources/platforms/zephyr/project/cmake/frameworks/tvm.cmake +1 -0
- resources/platforms/zephyr/project/cmake/frameworks/tvm_mlif.cmake +37 -0
- resources/platforms/zephyr/project/lib/CMakeLists.txt +13 -0
- resources/platforms/zephyr/project/lib/drivers/fake_input.c +10 -0
- resources/platforms/zephyr/project/lib/drivers/fake_input.h +8 -0
- resources/platforms/zephyr/project/lib/ml_interface/CMakeLists.txt +31 -0
- resources/platforms/zephyr/project/lib/ml_interface/default_data.c +8 -0
- resources/platforms/zephyr/project/lib/ml_interface/default_model_support/CMakeLists.txt +2 -0
- resources/platforms/zephyr/project/lib/ml_interface/default_model_support/process_input.c +17 -0
- resources/platforms/zephyr/project/lib/ml_interface/default_model_support/process_output.c +27 -0
- resources/platforms/zephyr/project/lib/ml_interface/ml_interface.c +36 -0
- resources/platforms/zephyr/project/lib/ml_interface/ml_interface.h +47 -0
- resources/platforms/zephyr/project/lib/ml_interface/ml_interface_tflm.cc +22 -0
- resources/platforms/zephyr/project/lib/ml_interface/ml_interface_tvm.c +22 -0
- resources/platforms/zephyr/project/lib/support/CMakeLists.txt +2 -0
- resources/platforms/zephyr/project/lib/support/dummy.c +0 -0
- resources/platforms/zephyr/project/lib/support/exit.h +8 -0
- resources/platforms/zephyr/project/lib/support/printing.h +11 -0
- resources/platforms/zephyr/project/lib/support/quantize.h +23 -0
- resources/platforms/zephyr/project/lib/targets/corstone300.c +62 -0
- resources/platforms/zephyr/project/lib/targets/default.c +2 -0
- resources/platforms/zephyr/project/lib/targets/etiss_pulpino.c +112 -0
- resources/platforms/zephyr/project/lib/targets/generic_riscv.c +112 -0
- resources/platforms/zephyr/project/lib/targets/riscv_qemu.c +112 -0
- resources/platforms/zephyr/project/lib/targets/target.h +2 -0
- resources/platforms/zephyr/project/prj.conf +11 -0
- resources/platforms/zephyr/project/sample.yaml +19 -0
- resources/platforms/zephyr/project/src/main.c +71 -0
- resources/platforms/zephyr/project2/CMakeLists.txt +72 -0
- resources/platforms/zephyr/project2/Kconfig +101 -0
- resources/platforms/zephyr/project2/README.rst +33 -0
- resources/platforms/zephyr/project2/cmake/AddAllSubdirs.cmake +21 -0
- resources/platforms/zephyr/project2/cmake/ChooseTarget.cmake +22 -0
- resources/platforms/zephyr/project2/cmake/LinkTFLite.cmake +223 -0
- resources/platforms/zephyr/project2/cmake/LinkTVM.cmake +68 -0
- resources/platforms/zephyr/project2/cmake/LookupClang.cmake +41 -0
- resources/platforms/zephyr/project2/cmake/backends/tflmc.cmake +5 -0
- resources/platforms/zephyr/project2/cmake/backends/tflmi.cmake +5 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmaot.cmake +10 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmaotplus.cmake +10 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmcg.cmake +10 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmllvm.cmake +8 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmrt.cmake +8 -0
- resources/platforms/zephyr/project2/cmake/extras.cmake +9 -0
- resources/platforms/zephyr/project2/cmake/features/auto_vectorize_gcc.cmake +65 -0
- resources/platforms/zephyr/project2/cmake/features/auto_vectorize_llvm.cmake +20 -0
- resources/platforms/zephyr/project2/cmake/features/cmsisnn.cmake +86 -0
- resources/platforms/zephyr/project2/cmake/features/muriscvnn.cmake +87 -0
- resources/platforms/zephyr/project2/cmake/frameworks/tflm.cmake +1 -0
- resources/platforms/zephyr/project2/cmake/frameworks/tflm_mlif.cmake +8 -0
- resources/platforms/zephyr/project2/cmake/frameworks/tvm.cmake +1 -0
- resources/platforms/zephyr/project2/cmake/frameworks/tvm_mlif.cmake +37 -0
- resources/platforms/zephyr/project2/default_data.c +8 -0
- resources/platforms/zephyr/project2/default_model_support/CMakeLists.txt +3 -0
- resources/platforms/zephyr/project2/default_model_support/process_input.c +17 -0
- resources/platforms/zephyr/project2/default_model_support/process_output.c +27 -0
- resources/platforms/zephyr/project2/lib/CMakeLists.txt +13 -0
- resources/platforms/zephyr/project2/lib/drivers/fake_input.c +10 -0
- resources/platforms/zephyr/project2/lib/drivers/fake_input.h +8 -0
- resources/platforms/zephyr/project2/lib/support/CMakeLists.txt +2 -0
- resources/platforms/zephyr/project2/lib/support/dummy.c +0 -0
- resources/platforms/zephyr/project2/lib/support/exit.h +8 -0
- resources/platforms/zephyr/project2/lib/support/printing.h +11 -0
- resources/platforms/zephyr/project2/lib/support/quantize.h +23 -0
- resources/platforms/zephyr/project2/lib/targets/corstone300.c +62 -0
- resources/platforms/zephyr/project2/lib/targets/default.c +2 -0
- resources/platforms/zephyr/project2/lib/targets/etiss_pulpino.c +112 -0
- resources/platforms/zephyr/project2/lib/targets/generic_riscv.c +112 -0
- resources/platforms/zephyr/project2/lib/targets/riscv_qemu.c +112 -0
- resources/platforms/zephyr/project2/lib/targets/target.h +2 -0
- resources/platforms/zephyr/project2/ml_interface.c +36 -0
- resources/platforms/zephyr/project2/ml_interface.h +47 -0
- resources/platforms/zephyr/project2/ml_interface_tflm.cc +22 -0
- resources/platforms/zephyr/project2/ml_interface_tvm.c +22 -0
- resources/platforms/zephyr/project2/prj.conf +13 -0
- resources/platforms/zephyr/project2/sample.yaml +19 -0
- resources/platforms/zephyr/project2/settings.json +6 -0
- resources/platforms/zephyr/project2/src/main.c +35 -0
- resources/pycharm/.run/README.md +73 -0
- resources/pycharm/.run/step1_ init env.run.xml +24 -0
- resources/pycharm/.run/step2_ setup.run.xml +25 -0
- resources/pycharm/.run/step3_ run resnet on pulpxpulpissimo.run.xml +25 -0
- resources/templates/default.yml.j2 +258 -0
- resources/templates/dev.yml.j2 +212 -0
- resources/templates/minimal.yml.j2 +234 -0
- resources/templates/phi.yml.j2 +282 -0
- resources/templates/pulp.yml.j2 +267 -0
- resources/templates/research.yml.j2 +237 -0
- resources/templates/tumeda.yml.j2 +239 -0
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2022 TUM Department of Electrical and Computer Engineering.
|
|
3
|
+
#
|
|
4
|
+
# This file is part of MLonMCU.
|
|
5
|
+
# See https://github.com/tum-ei-eda/mlonmcu.git for further info.
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
"""ESP-IDF Platform"""
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
import time
|
|
23
|
+
import signal
|
|
24
|
+
import shutil
|
|
25
|
+
import tempfile
|
|
26
|
+
import subprocess
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
import pkg_resources
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
from mlonmcu.setup import utils
|
|
32
|
+
from mlonmcu.artifact import Artifact, ArtifactFormat
|
|
33
|
+
from mlonmcu.logging import get_logger
|
|
34
|
+
from mlonmcu.target.target import Target
|
|
35
|
+
from mlonmcu.config import str2bool
|
|
36
|
+
|
|
37
|
+
from ..platform import CompilePlatform, TargetPlatform
|
|
38
|
+
from .espidf_target import create_espidf_platform_target, get_espidf_platform_targets
|
|
39
|
+
|
|
40
|
+
logger = get_logger()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def get_project_template(name="project"):
|
|
44
|
+
espidf_templates = pkg_resources.resource_listdir("mlonmcu", os.path.join("..", "resources", "platforms", "espidf"))
|
|
45
|
+
if name not in espidf_templates:
|
|
46
|
+
return None
|
|
47
|
+
fname = pkg_resources.resource_filename("mlonmcu", os.path.join("..", "resources", "platforms", "espidf", name))
|
|
48
|
+
return fname
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class EspIdfPlatform(CompilePlatform, TargetPlatform):
|
|
52
|
+
"""ESP-IDF Platform class."""
|
|
53
|
+
|
|
54
|
+
FEATURES = CompilePlatform.FEATURES + TargetPlatform.FEATURES + ["benchmark"]
|
|
55
|
+
|
|
56
|
+
DEFAULTS = {
|
|
57
|
+
**CompilePlatform.DEFAULTS,
|
|
58
|
+
**TargetPlatform.DEFAULTS,
|
|
59
|
+
"project_template": None,
|
|
60
|
+
"project_dir": None,
|
|
61
|
+
"port": None,
|
|
62
|
+
"baud": 115200,
|
|
63
|
+
"use_idf_monitor": True,
|
|
64
|
+
"wait_for_user": True,
|
|
65
|
+
"flash_only": False,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
REQUIRED = ["espidf.install_dir", "espidf.src_dir"]
|
|
69
|
+
|
|
70
|
+
def __init__(self, features=None, config=None):
|
|
71
|
+
super().__init__(
|
|
72
|
+
"espidf",
|
|
73
|
+
features=features,
|
|
74
|
+
config=config,
|
|
75
|
+
)
|
|
76
|
+
self.tempdir = None
|
|
77
|
+
self.project_name = "app"
|
|
78
|
+
self.project_dir = None
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def espidf_install_dir(self):
|
|
82
|
+
return Path(self.config["espidf.install_dir"])
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def espidf_src_dir(self):
|
|
86
|
+
return Path(self.config["espidf.src_dir"])
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def idf_exe(self):
|
|
90
|
+
return self.espidf_src_dir / "tools" / "idf.py"
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def use_idf_monitor(self):
|
|
94
|
+
value = self.config["use_idf_monitor"]
|
|
95
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def wait_for_user(self):
|
|
99
|
+
value = self.config["wait_for_user"]
|
|
100
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def flash_only(self):
|
|
104
|
+
# TODO: get rid of this
|
|
105
|
+
value = self.config["flash_only"]
|
|
106
|
+
return str2bool(value) if not isinstance(value, (bool, int)) else value
|
|
107
|
+
|
|
108
|
+
def invoke_idf_exe(self, *args, **kwargs):
|
|
109
|
+
env = os.environ.copy()
|
|
110
|
+
env["IDF_PATH"] = str(self.espidf_src_dir)
|
|
111
|
+
env["IDF_TOOLS_PATH"] = str(self.espidf_install_dir)
|
|
112
|
+
cmd = (
|
|
113
|
+
". "
|
|
114
|
+
+ str(self.espidf_src_dir / "export.sh")
|
|
115
|
+
+ f" && {self.idf_exe} "
|
|
116
|
+
# + f" > /dev/null && {self.idf_exe} "
|
|
117
|
+
+ " ".join([str(arg) for arg in args])
|
|
118
|
+
)
|
|
119
|
+
out = utils.exec_getout(
|
|
120
|
+
cmd, shell=True, env=env, **kwargs, executable="/bin/bash"
|
|
121
|
+
) # TODO: using shell=True is insecure but right now we can not avoid it?
|
|
122
|
+
return out
|
|
123
|
+
|
|
124
|
+
def init_directory(self, path=None, context=None):
|
|
125
|
+
if self.project_dir is not None:
|
|
126
|
+
self.project_dir.mkdir(exist_ok=True)
|
|
127
|
+
logger.debug("Project directory already initialized")
|
|
128
|
+
return
|
|
129
|
+
dir_name = self.name
|
|
130
|
+
if path is not None:
|
|
131
|
+
self.project_dir = Path(path)
|
|
132
|
+
elif self.config["project_dir"] is not None:
|
|
133
|
+
self.project_dir = Path(self.config["project_dir"])
|
|
134
|
+
else:
|
|
135
|
+
if context:
|
|
136
|
+
assert "temp" in context.environment.paths
|
|
137
|
+
self.project_dir = (
|
|
138
|
+
context.environment.paths["temp"].path / dir_name
|
|
139
|
+
) # TODO: Need to lock this for parallel builds
|
|
140
|
+
else:
|
|
141
|
+
logger.debug(
|
|
142
|
+
"Creating temporary directory because no context was available "
|
|
143
|
+
"and 'espidf.project_dir' was not supplied"
|
|
144
|
+
)
|
|
145
|
+
self.tempdir = tempfile.TemporaryDirectory()
|
|
146
|
+
self.project_dir = Path(self.tempdir.name) / dir_name
|
|
147
|
+
logger.debug("Temporary project directory: %s", self.project_dir)
|
|
148
|
+
self.project_dir.mkdir(exist_ok=True)
|
|
149
|
+
|
|
150
|
+
def get_supported_targets(self):
|
|
151
|
+
text = self.invoke_idf_exe("--list-targets", live=self.print_outputs, print_output=False)
|
|
152
|
+
# Warning: This will fail if a python executable is NOT available in the system. Aliasing
|
|
153
|
+
# python3 to python will not work. Not sure how this would handle a system which only has python2 installed?
|
|
154
|
+
target_names = text.split("\n")
|
|
155
|
+
|
|
156
|
+
def filter_names(x):
|
|
157
|
+
ret = []
|
|
158
|
+
for x in reversed(x):
|
|
159
|
+
if len(x) > 0:
|
|
160
|
+
ret.append(x)
|
|
161
|
+
else:
|
|
162
|
+
if len(ret) > 0:
|
|
163
|
+
break
|
|
164
|
+
else:
|
|
165
|
+
continue
|
|
166
|
+
return reversed(ret)
|
|
167
|
+
|
|
168
|
+
target_names = filter_names(target_names)
|
|
169
|
+
|
|
170
|
+
return [name for name in target_names if len(name) > 0 and " " not in name]
|
|
171
|
+
|
|
172
|
+
def create_target(self, name):
|
|
173
|
+
assert name in self.get_supported_targets(), f"{name} is not a valid ESP-IDF target"
|
|
174
|
+
targets = get_espidf_platform_targets()
|
|
175
|
+
if name in targets:
|
|
176
|
+
base = targets[name]
|
|
177
|
+
else:
|
|
178
|
+
base = Target
|
|
179
|
+
return create_espidf_platform_target(name, self, base=base)
|
|
180
|
+
|
|
181
|
+
@property
|
|
182
|
+
def project_template(self):
|
|
183
|
+
return self.config["project_template"]
|
|
184
|
+
|
|
185
|
+
@property
|
|
186
|
+
def port(self):
|
|
187
|
+
return self.config["port"]
|
|
188
|
+
|
|
189
|
+
@property
|
|
190
|
+
def baud(self):
|
|
191
|
+
return self.config["baud"]
|
|
192
|
+
|
|
193
|
+
def close(self):
|
|
194
|
+
if self.tempdir:
|
|
195
|
+
self.tempdir.cleanup()
|
|
196
|
+
|
|
197
|
+
def check(self):
|
|
198
|
+
if not shutil.which(self.idf_exe):
|
|
199
|
+
raise RuntimeError(f"It seems like '{self.idf_exe}' is not available. Make sure to setup your environment!")
|
|
200
|
+
|
|
201
|
+
def prepare(self, target, src):
|
|
202
|
+
self.init_directory()
|
|
203
|
+
self.check()
|
|
204
|
+
template_dir = self.project_template
|
|
205
|
+
if template_dir is None:
|
|
206
|
+
template_dir = get_project_template()
|
|
207
|
+
else:
|
|
208
|
+
template_dir = Path(template_dir)
|
|
209
|
+
if not template_dir.is_dir():
|
|
210
|
+
template_dir = get_project_template(name=str(template_dir))
|
|
211
|
+
assert template_dir is not None, f"Provided project template does not exists: {template_dir}"
|
|
212
|
+
shutil.copytree(template_dir, self.project_dir, dirs_exist_ok=True)
|
|
213
|
+
|
|
214
|
+
def write_defaults(filename):
|
|
215
|
+
defs = self.definitions
|
|
216
|
+
with open(filename, "w", encoding="utf-8") as f:
|
|
217
|
+
f.write("CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y\n")
|
|
218
|
+
if self.debug:
|
|
219
|
+
f.write("CONFIG_OPTIMIZATION_LEVEL_DEBUG=y\n")
|
|
220
|
+
f.write("CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y\n")
|
|
221
|
+
else:
|
|
222
|
+
# Trying to reduce the binary size as much as possible
|
|
223
|
+
# (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/performance/size.html)
|
|
224
|
+
f.write("CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y\n")
|
|
225
|
+
f.write("CONFIG_BOOTLOADER_LOG_LEVEL=0\n")
|
|
226
|
+
f.write("CONFIG_BOOT_ROM_LOG_ALWAYS_OFF=y\n")
|
|
227
|
+
f.write("CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y\n")
|
|
228
|
+
f.write("CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL=0\n")
|
|
229
|
+
f.write("CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y\n")
|
|
230
|
+
f.write("CONFIG_HAL_DEFAULT_ASSERTION_LEVEL=0\n")
|
|
231
|
+
f.write("CONFIG_LOG_DEFAULT_LEVEL_NONE=y\n")
|
|
232
|
+
f.write("CONFIG_LOG_DEFAULT_LEVEL=0\n")
|
|
233
|
+
f.write("CONFIG_LOG_MAXIMUM_LEVEL=0\n")
|
|
234
|
+
f.write("CONFIG_NEWLIB_NANO_FORMAT=y\n")
|
|
235
|
+
f.write("CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE=y\n")
|
|
236
|
+
f.write("CONFIG_OPTIMIZATION_LEVEL_RELEASE=y\n")
|
|
237
|
+
optimize_for_size = True
|
|
238
|
+
if optimize_for_size:
|
|
239
|
+
f.write("CONFIG_COMPILER_OPTIMIZATION_SIZE=y\n")
|
|
240
|
+
else:
|
|
241
|
+
f.write("CONFIG_COMPILER_OPTIMIZATION_PERF=y\n")
|
|
242
|
+
watchdog_sec = 60
|
|
243
|
+
f.write(f"CONFIG_ESP_TASK_WDT_TIMEOUT_S={watchdog_sec}\n")
|
|
244
|
+
f.write(f'CONFIG_MLONMCU_CODEGEN_DIR="{src}"\n')
|
|
245
|
+
for key, value in defs.items():
|
|
246
|
+
if isinstance(value, bool):
|
|
247
|
+
value = "y" if value else "n"
|
|
248
|
+
else:
|
|
249
|
+
value = f'"{value}"'
|
|
250
|
+
f.write(f"CONFIG_{key}={value}\n")
|
|
251
|
+
|
|
252
|
+
write_defaults(self.project_dir / "sdkconfig.defaults")
|
|
253
|
+
idfArgs = [
|
|
254
|
+
"-C",
|
|
255
|
+
self.project_dir,
|
|
256
|
+
"set-target",
|
|
257
|
+
target.name,
|
|
258
|
+
]
|
|
259
|
+
out = self.invoke_idf_exe(*idfArgs, live=self.print_outputs)
|
|
260
|
+
return out
|
|
261
|
+
|
|
262
|
+
def get_idf_cmake_args(self):
|
|
263
|
+
cmake_defs = {"CMAKE_BUILD_TYPE": "Debug" if self.debug else "Release"}
|
|
264
|
+
return [f"-D{key}={value}" for key, value in cmake_defs.items()]
|
|
265
|
+
|
|
266
|
+
def compile(self, target, src=None):
|
|
267
|
+
out = ""
|
|
268
|
+
# TODO: build with cmake options
|
|
269
|
+
out += self.prepare(target, src)
|
|
270
|
+
# TODO: support self.num_threads (e.g. patch esp-idf)
|
|
271
|
+
idfArgs = [
|
|
272
|
+
"-C",
|
|
273
|
+
self.project_dir,
|
|
274
|
+
*self.get_idf_cmake_args(),
|
|
275
|
+
"build",
|
|
276
|
+
]
|
|
277
|
+
out += self.invoke_idf_exe(*idfArgs, live=self.print_outputs)
|
|
278
|
+
return out
|
|
279
|
+
|
|
280
|
+
def generate_elf(self, src, target, model=None, data_file=None):
|
|
281
|
+
artifacts = []
|
|
282
|
+
out = self.compile(target, src=src)
|
|
283
|
+
elf_name = self.project_name + ".elf"
|
|
284
|
+
elf_file = self.project_dir / "build" / elf_name
|
|
285
|
+
# TODO: just use path instead of raw data?
|
|
286
|
+
if self.tempdir:
|
|
287
|
+
# Warning: The porject context will get destroyed afterwards wehen using a temporory directory
|
|
288
|
+
with open(elf_file, "rb") as handle:
|
|
289
|
+
data = handle.read()
|
|
290
|
+
artifact = Artifact("generic_mlif", raw=data, fmt=ArtifactFormat.RAW)
|
|
291
|
+
artifacts.append(artifact)
|
|
292
|
+
else:
|
|
293
|
+
artifact = Artifact(elf_name, path=elf_file, fmt=ArtifactFormat.PATH)
|
|
294
|
+
artifacts.append(artifact)
|
|
295
|
+
metrics = self.get_metrics(elf_file)
|
|
296
|
+
content = metrics.to_csv(include_optional=True) # TODO: store df instead?
|
|
297
|
+
metrics_artifact = Artifact("metrics.csv", content=content, fmt=ArtifactFormat.TEXT)
|
|
298
|
+
artifacts.append(metrics_artifact)
|
|
299
|
+
stdout_artifact = Artifact(
|
|
300
|
+
"espidf_out.log", content=out, fmt=ArtifactFormat.TEXT # TODO: split into one file per command
|
|
301
|
+
) # TODO: rename to tvmaot_out.log?
|
|
302
|
+
artifacts.append(stdout_artifact)
|
|
303
|
+
self.artifacts = artifacts
|
|
304
|
+
|
|
305
|
+
def get_idf_serial_args(self, monitor=False):
|
|
306
|
+
args = []
|
|
307
|
+
if self.port:
|
|
308
|
+
args.extend(["-p", self.port])
|
|
309
|
+
if self.baud:
|
|
310
|
+
args.extend(["-B" if monitor else "-b", self.baud])
|
|
311
|
+
return args
|
|
312
|
+
|
|
313
|
+
def flash(self, elf, target, timeout=120):
|
|
314
|
+
# Ignore elf, as we use self.project_dir instead
|
|
315
|
+
# TODO: add alternative approach which allows passing elf instead
|
|
316
|
+
if elf is not None:
|
|
317
|
+
logger.debug("Ignoring ELF file for espidf platform")
|
|
318
|
+
# TODO: implement timeout
|
|
319
|
+
# TODO: make sure that already compiled? -> error or just call compile routine?
|
|
320
|
+
if self.wait_for_user: # INTERACTIVE
|
|
321
|
+
answer = input(
|
|
322
|
+
f"Make sure that the device '{target.name}' is connected before you press [Enter]"
|
|
323
|
+
+ " (Type 'Abort' to cancel)"
|
|
324
|
+
)
|
|
325
|
+
if answer.lower() == "abort":
|
|
326
|
+
return ""
|
|
327
|
+
logger.debug("Flashing target software")
|
|
328
|
+
|
|
329
|
+
idfArgs = [
|
|
330
|
+
"-C",
|
|
331
|
+
self.project_dir,
|
|
332
|
+
*self.get_idf_cmake_args(),
|
|
333
|
+
"flash",
|
|
334
|
+
*self.get_idf_serial_args(),
|
|
335
|
+
]
|
|
336
|
+
self.invoke_idf_exe(*idfArgs, live=self.print_outputs)
|
|
337
|
+
|
|
338
|
+
def monitor(self, target, timeout=60):
|
|
339
|
+
if self.flash_only:
|
|
340
|
+
return ""
|
|
341
|
+
|
|
342
|
+
if self.use_idf_monitor:
|
|
343
|
+
import psutil
|
|
344
|
+
|
|
345
|
+
def _kill_monitor():
|
|
346
|
+
import psutil
|
|
347
|
+
for proc in psutil.process_iter():
|
|
348
|
+
# check whether the process name matches
|
|
349
|
+
cmdline = " ".join(proc.cmdline())
|
|
350
|
+
if "idf_monitor.py" in cmdline: # TODO: do something less "dangerous"?
|
|
351
|
+
proc.kill()
|
|
352
|
+
|
|
353
|
+
def _monitor_helper(*args, verbose=False, start_match=None, end_match=None, timeout=60):
|
|
354
|
+
# start_match and end_match are inclusive
|
|
355
|
+
if timeout:
|
|
356
|
+
pass # TODO: implement timeout
|
|
357
|
+
found_start = start_match is None
|
|
358
|
+
logger.debug("- Executing: %s", str(args))
|
|
359
|
+
outStr = ""
|
|
360
|
+
env = os.environ.copy()
|
|
361
|
+
env["IDF_PATH"] = str(self.espidf_src_dir)
|
|
362
|
+
env["IDF_TOOLS_PATH"] = str(self.espidf_install_dir)
|
|
363
|
+
cmd = (
|
|
364
|
+
". "
|
|
365
|
+
+ str(self.espidf_src_dir / "export.sh")
|
|
366
|
+
+ f"> /dev/null && {self.idf_exe} "
|
|
367
|
+
+ " ".join([str(arg) for arg in args])
|
|
368
|
+
)
|
|
369
|
+
process = subprocess.Popen(
|
|
370
|
+
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, executable="/bin/bash", env=env
|
|
371
|
+
)
|
|
372
|
+
try:
|
|
373
|
+
exit_code = None
|
|
374
|
+
for line in process.stdout:
|
|
375
|
+
new_line = line.decode(errors="replace")
|
|
376
|
+
if verbose:
|
|
377
|
+
print(new_line.replace("\n", ""))
|
|
378
|
+
if start_match and start_match in new_line:
|
|
379
|
+
outStr = new_line
|
|
380
|
+
found_start = True
|
|
381
|
+
else:
|
|
382
|
+
outStr = outStr + new_line
|
|
383
|
+
if found_start:
|
|
384
|
+
if end_match and end_match in new_line:
|
|
385
|
+
_kill_monitor()
|
|
386
|
+
process.terminate()
|
|
387
|
+
exit_code = 0
|
|
388
|
+
while exit_code is None:
|
|
389
|
+
exit_code = process.poll()
|
|
390
|
+
if not verbose and exit_code != 0:
|
|
391
|
+
logger.error(outStr)
|
|
392
|
+
assert exit_code == 0, "The process returned an non-zero exit code {}! (CMD: `{}`)".format(
|
|
393
|
+
exit_code, cmd
|
|
394
|
+
)
|
|
395
|
+
except KeyboardInterrupt:
|
|
396
|
+
logger.debug("Interrupted subprocess. Sending SIGINT signal...")
|
|
397
|
+
_kill_monitor()
|
|
398
|
+
pid = process.pid
|
|
399
|
+
os.kill(pid, signal.SIGINT)
|
|
400
|
+
os.system("reset")
|
|
401
|
+
return outStr
|
|
402
|
+
|
|
403
|
+
logger.debug("Monitoring target software")
|
|
404
|
+
# TODO: implement timeout
|
|
405
|
+
idfArgs = [
|
|
406
|
+
"-C",
|
|
407
|
+
self.project_dir,
|
|
408
|
+
*self.get_idf_cmake_args(),
|
|
409
|
+
"monitor",
|
|
410
|
+
*self.get_idf_serial_args(monitor=True),
|
|
411
|
+
]
|
|
412
|
+
return _monitor_helper(
|
|
413
|
+
*idfArgs,
|
|
414
|
+
verbose=self.print_outputs,
|
|
415
|
+
start_match="MLonMCU: START",
|
|
416
|
+
end_match="MLonMCU: STOP",
|
|
417
|
+
timeout=timeout,
|
|
418
|
+
)
|
|
419
|
+
else:
|
|
420
|
+
port = target.port
|
|
421
|
+
if port is None:
|
|
422
|
+
# Falling back to 'espidf.baud'
|
|
423
|
+
assert self.port is not None, f"If using custom serial monitor, please provide '{target.name}.port'"
|
|
424
|
+
port = self.port
|
|
425
|
+
baud = target.baud
|
|
426
|
+
if baud is None:
|
|
427
|
+
# Falling back to 'espidf.baud'
|
|
428
|
+
assert self.baud is not None, f"If using custom serial monitor, please provide '{target.name}.baud'"
|
|
429
|
+
baud = self.baud
|
|
430
|
+
|
|
431
|
+
def _monitor_helper2(port, baud, verbose=False, start_match=None, end_match=None, timeout=60):
|
|
432
|
+
# Local import to make this only required for real HW targets
|
|
433
|
+
import serial
|
|
434
|
+
|
|
435
|
+
# start_match and end_match are inclusive
|
|
436
|
+
found_start = start_match is None
|
|
437
|
+
outStr = ""
|
|
438
|
+
if timeout:
|
|
439
|
+
pass # TODO: implement timeout
|
|
440
|
+
# The following is a custom initialization sequence inspired by
|
|
441
|
+
# (https://github.com/espressif/esp-idf/blob/master/tools/idf_monitor_base/serial_reader.py)
|
|
442
|
+
high = False
|
|
443
|
+
low = True
|
|
444
|
+
ser = serial.Serial(port, baud)
|
|
445
|
+
ser.close()
|
|
446
|
+
ser.dtr = False
|
|
447
|
+
ser.rts = False
|
|
448
|
+
time.sleep(1)
|
|
449
|
+
ser.dtr = low
|
|
450
|
+
ser.rts = high
|
|
451
|
+
ser.dtr = ser.dtr
|
|
452
|
+
ser.open()
|
|
453
|
+
ser.dtr = high
|
|
454
|
+
ser.rts = low
|
|
455
|
+
ser.dtr = ser.dtr
|
|
456
|
+
time.sleep(0.002)
|
|
457
|
+
ser.rts = high
|
|
458
|
+
ser.dtr = ser.dtr
|
|
459
|
+
try:
|
|
460
|
+
while True:
|
|
461
|
+
try:
|
|
462
|
+
ser_bytes = ser.readline()
|
|
463
|
+
new_line = ser_bytes.decode("utf-8", errors="replace")
|
|
464
|
+
if verbose:
|
|
465
|
+
print(new_line.replace("\n", ""))
|
|
466
|
+
if start_match and start_match in new_line:
|
|
467
|
+
outStr = new_line
|
|
468
|
+
found_start = True
|
|
469
|
+
else:
|
|
470
|
+
outStr = outStr + new_line
|
|
471
|
+
if found_start:
|
|
472
|
+
if end_match and end_match in new_line:
|
|
473
|
+
break
|
|
474
|
+
except KeyboardInterrupt:
|
|
475
|
+
logger.warning("Stopped processing serial port (KeyboardInterrupt)")
|
|
476
|
+
finally:
|
|
477
|
+
ser.close()
|
|
478
|
+
return outStr
|
|
479
|
+
|
|
480
|
+
logger.debug("Monitoring target software")
|
|
481
|
+
# TODO: implement timeout
|
|
482
|
+
return _monitor_helper2(
|
|
483
|
+
port,
|
|
484
|
+
baud,
|
|
485
|
+
verbose=self.print_outputs,
|
|
486
|
+
start_match="MLonMCU: START",
|
|
487
|
+
end_match="MLonMCU: STOP",
|
|
488
|
+
timeout=timeout,
|
|
489
|
+
)
|