mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-19 09:25:54 +08:00
添加智能灯固件代码
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(gcov_example)
|
||||
|
||||
idf_create_coverage_report(${CMAKE_CURRENT_BINARY_DIR}/coverage_report)
|
||||
idf_clean_coverage_report(${CMAKE_CURRENT_BINARY_DIR}/coverage_report)
|
||||
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := gcov_example
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
|
||||
GCOV := $(call dequote,$(CONFIG_SDK_TOOLPREFIX))gcov
|
||||
REPORT_DIR := $(BUILD_DIR_BASE)/coverage_report
|
||||
|
||||
pre-cov-report:
|
||||
echo "Generating coverage report in: $(REPORT_DIR)"
|
||||
echo "Using gcov: $(GCOV)"
|
||||
mkdir -p $(REPORT_DIR)/html
|
||||
|
||||
lcov-report: | pre-cov-report
|
||||
echo "WARNING: lcov-report is deprecated. Please use gcovr-report instead."
|
||||
lcov --gcov-tool $(GCOV) -c -d $(BUILD_DIR_BASE) -o $(REPORT_DIR)/$(PROJECT_NAME).info
|
||||
genhtml -o $(REPORT_DIR)/html $(REPORT_DIR)/$(PROJECT_NAME).info
|
||||
|
||||
gcovr-report: | check_python_dependencies pre-cov-report
|
||||
cd $(BUILD_DIR_BASE)
|
||||
gcovr -r $(PROJECT_PATH) --gcov-executable $(GCOV) -s --html-details $(REPORT_DIR)/html/index.html
|
||||
|
||||
cov-data-clean:
|
||||
echo "Remove coverage data files..."
|
||||
find $(BUILD_DIR_BASE) -name "*.gcda" -exec rm {} +
|
||||
rm -rf $(REPORT_DIR)
|
||||
|
||||
.PHONY: lcov-report gcovr-report cov-data-clean
|
||||
@@ -0,0 +1,150 @@
|
||||
| Supported Targets | ESP32 |
|
||||
| ----------------- | ----- |
|
||||
|
||||
# Blink Example With Coverage Info (Gcov)
|
||||
|
||||
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
The following example demonstrates how to compile an ESP-IDF project to generate code coverage data, and how generate a code coverage report using Gcov or Lcov. Refer to the [Gcov Guide](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/app_trace.html#gcov-source-code-coverage) for more details on the code coverage features supported in ESP-IDF.
|
||||
|
||||
This example implements a simple blink application but with code coverage enabled. The example will demonstrate the following features:
|
||||
* How to compile a project with coverage info enabled.
|
||||
* Various methods of dumping code coverage data (e.g. Instant Run-Time Dump and Hard-coded Dump).
|
||||
* How to generate a code coverage report.
|
||||
|
||||
## How to use example
|
||||
|
||||
### Hardware Required
|
||||
|
||||
To run this example, you need an ESP32 dev board connected to a JTAG adapter, which can come in the following forms:
|
||||
|
||||
* [ESP-WROVER-KIT](https://docs.espressif.com/projects/esp-idf/en/latest/hw-reference/modules-and-boards.html#esp-wrover-kit-v4-1) which integrates an on-board JTAG adapter. Ensure that the [required jumpers to enable JTAG are connected](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/get-started-wrover-kit.html#setup-options) on the WROVER-KIT.
|
||||
* ESP32 core board (e.g. ESP32-DevKitC) can also work as long as you connect it to an external JTAG adapter (e.g. FT2232H, J-LINK).
|
||||
|
||||
This example will assume that that an ESP-WROVER-KIT is used.
|
||||
|
||||
1. Connect the JTAG interface to ESP32 board, and power up both the JTAG and ESP32. For details about how to set up JTAG interface, please see [JTAG Debugging](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/jtag-debugging/index.html).
|
||||
|
||||
2. After connecting JTAG interface, you need to [Run OpenOCD](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/jtag-debugging/index.html#run-openocd).
|
||||
|
||||
3. Open a separate terminal window and run telnet by entering the command below. The telnet terminal window is used to feed commands to OpenOCD:
|
||||
|
||||
```bash
|
||||
telnet localhost 4444
|
||||
```
|
||||
|
||||
### Configure the project
|
||||
|
||||
```
|
||||
idf.py menuconfig
|
||||
```
|
||||
|
||||
The example will enable the following options by default:
|
||||
|
||||
* Enable the Application Tracing Module under `Component config -> Application Level Tracing -> Data Destination` by choosing `Trace memory`.
|
||||
* Enable GCOV to host interface under `Component config -> Application Level Tracing -> GCOV to Host Enable`.
|
||||
* Enable OpenOCD Debug Stubs under `Component config -> ESP32-specific -> OpenOCD debug stubs`
|
||||
|
||||
### Build, Flash, and Run
|
||||
|
||||
Build the project and flash it to the board, then run monitor tool to view serial output:
|
||||
|
||||
```
|
||||
idf.py -p PORT flash monitor
|
||||
```
|
||||
|
||||
(Replace PORT with the name of the serial port to use.)
|
||||
|
||||
(To exit the serial monitor, type ``Ctrl-]``.)
|
||||
|
||||
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
|
||||
|
||||
## Example Output
|
||||
|
||||
### 1. Hard-coded Dump
|
||||
|
||||
The example will initially execute two hard-coded dumps. Therefore, when the application outputs `Ready to dump GCOV data...`, users should execute the `esp gcov dump` OpenOCD command. The example should output the following:
|
||||
|
||||
```
|
||||
blink_dummy_func: Counter = 0
|
||||
some_dummy_func: Counter = 0
|
||||
Ready to dump GCOV data...
|
||||
GCOV data have been dumped.
|
||||
blink_dummy_func: Counter = 1
|
||||
some_dummy_func: Counter = 2
|
||||
Ready to dump GCOV data...
|
||||
GCOV data have been dumped.
|
||||
```
|
||||
|
||||
### 2. Instant Run-Time Dump
|
||||
|
||||
After the two hard-coded dumps, the example will continue looping through it's main blink function. Users can call `esp gcov` OpenOCD command to trigger an instant run-time dump. The output should resemble the following:
|
||||
|
||||
```
|
||||
blink_dummy_func: Counter = 2
|
||||
some_dummy_func: Counter = 4
|
||||
blink_dummy_func: Counter = 3
|
||||
some_dummy_func: Counter = 6
|
||||
blink_dummy_func: Counter = 4
|
||||
some_dummy_func: Counter = 8
|
||||
blink_dummy_func: Counter = 5
|
||||
some_dummy_func: Counter = 10
|
||||
blink_dummy_func: Counter = 6
|
||||
some_dummy_func: Counter = 12
|
||||
blink_dummy_func: Counter = 7
|
||||
some_dummy_func: Counter = 14
|
||||
blink_dummy_func: Counter = 8
|
||||
some_dummy_func: Counter = 16
|
||||
blink_dummy_func: Counter = 9
|
||||
some_dummy_func: Counter = 18
|
||||
blink_dummy_func: Counter = 10
|
||||
some_dummy_func: Counter = 20
|
||||
...
|
||||
```
|
||||
|
||||
### Generating Gcovr Report
|
||||
|
||||
After dumping one or more times, a coverage report can be generated by calling `cmake --build build/ --target gcovr-report`. This should result in an HTML code coverage report being generated in the build directory.
|
||||
|
||||
To clean Gcov and report related data from the build directory, call `cmake --build build/ --target cov-data-clean`
|
||||
|
||||
The following log should be output when generating the coverage report:
|
||||
|
||||
```
|
||||
[1/2] Generating coverage report in: /home/user/esp/esp-idf/examples/system/gcov/build/coverage_report
|
||||
Using gcov: xtensa-esp32-elf-gcov
|
||||
[2/2] cd /home/user/esp/esp-idf/examples/system/gcov/build && gcovr -r /home/user/esp/esp-idf/examples/system/gcov...a-esp32-elf-gcov -s --html-details /home/user/esp/esp-idf/examples/system/gcov/build/coverage_report/html/index.htm
|
||||
lines: 100.0% (27 out of 27)
|
||||
branches: 100.0% (2 out of 2)
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### OpenOCD Out of Sync
|
||||
|
||||
If the following log is output when issuing an OpenOCD command via telnet, it could indicate that OpenOCD and the ESP32 are out of sync. This occurs when the ESP32 is externally reset whilst connected to OpenOCD (e.g., by pressing the EN button).
|
||||
|
||||
```
|
||||
Open On-Chip Debugger
|
||||
> esp gcov dump
|
||||
Target halted. PRO_CPU: PC=0x4008AFF4 (active) APP_CPU: PC=0x400E396E
|
||||
Total trace memory: 16384 bytes
|
||||
Connect targets...
|
||||
Target halted. PRO_CPU: PC=0x400D5D74 (active) APP_CPU: PC=0x400E396E
|
||||
timed out while waiting for target halted / 1 - 2
|
||||
Failed to wait halt on bp target (-4)!
|
||||
Failed to halt targets (-4)!
|
||||
Failed to connect to targets (-4)!
|
||||
```
|
||||
|
||||
This issue can be resolved in the following ways:
|
||||
* Reset the board by issuing the `reset` command via telnet
|
||||
* Restart OpenOCD
|
||||
|
||||
### gcovr not found
|
||||
|
||||
gcovr can be installed from the package database of your operating system or directly as a Python package, e.g:
|
||||
|
||||
```
|
||||
python -m pip install gcovr
|
||||
```
|
||||
@@ -0,0 +1,6 @@
|
||||
idf_component_register(SRCS "some_funcs.c"
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
set_source_files_properties(some_funcs.c
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
--coverage)
|
||||
@@ -0,0 +1,6 @@
|
||||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
|
||||
CFLAGS += --coverage
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
void some_dummy_func(void)
|
||||
{
|
||||
static int i;
|
||||
printf("some_dummy_func: Counter = %d\n", i++);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
from __future__ import unicode_literals
|
||||
from pexpect import TIMEOUT
|
||||
from ttfw_idf import Utility
|
||||
import os
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="test_jtag_arm")
|
||||
def test_examples_gcov(env, extra_data):
|
||||
|
||||
rel_project_path = os.path.join('examples', 'system', 'gcov')
|
||||
dut = env.get_dut('gcov', rel_project_path)
|
||||
idf_path = dut.app.get_sdk_path()
|
||||
proj_path = os.path.join(idf_path, rel_project_path)
|
||||
|
||||
with ttfw_idf.OCDProcess(os.path.join(proj_path, 'openocd.log')):
|
||||
with ttfw_idf.TelnetProcess(os.path.join(proj_path, 'telnet.log')) as telnet_p:
|
||||
dut.start_app()
|
||||
|
||||
def expect_counter_output(loop, timeout=10):
|
||||
dut.expect_all('blink_dummy_func: Counter = {}'.format(loop),
|
||||
'some_dummy_func: Counter = {}'.format(loop * 2),
|
||||
timeout=timeout)
|
||||
|
||||
expect_counter_output(0, timeout=20)
|
||||
dut.expect('Ready to dump GCOV data...', timeout=5)
|
||||
|
||||
def dump_coverage():
|
||||
try:
|
||||
telnet_p.pexpect_proc.sendline('esp gcov dump')
|
||||
telnet_p.pexpect_proc.expect_exact('Targets connected.')
|
||||
telnet_p.pexpect_proc.expect_exact('gcov_example_main.c.gcda')
|
||||
telnet_p.pexpect_proc.expect_exact('gcov_example_func.c.gcda')
|
||||
telnet_p.pexpect_proc.expect_exact('some_funcs.c.gcda')
|
||||
telnet_p.pexpect_proc.expect_exact('Targets disconnected.')
|
||||
except TIMEOUT:
|
||||
# Print what is happening with DUT. Limit the size if it is in loop and generating output.
|
||||
Utility.console_log(dut.read(size=1000))
|
||||
raise
|
||||
|
||||
dump_coverage()
|
||||
dut.expect('GCOV data have been dumped.', timeout=5)
|
||||
expect_counter_output(1)
|
||||
dut.expect('Ready to dump GCOV data...', timeout=5)
|
||||
dump_coverage()
|
||||
dut.expect('GCOV data have been dumped.', timeout=5)
|
||||
|
||||
for i in range(2, 6):
|
||||
expect_counter_output(i)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_examples_gcov()
|
||||
@@ -0,0 +1,8 @@
|
||||
idf_component_register(SRCS "gcov_example_main.c"
|
||||
"gcov_example_func.c"
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
set_source_files_properties(gcov_example_main.c
|
||||
gcov_example_func.c
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
--coverage)
|
||||
@@ -0,0 +1,14 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
config BLINK_GPIO
|
||||
int "Blink GPIO number"
|
||||
range 0 34
|
||||
default 5
|
||||
help
|
||||
GPIO number (IOxx) to blink on and off.
|
||||
|
||||
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink.
|
||||
|
||||
GPIOs 35-39 are input-only so cannot be used as outputs.
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,6 @@
|
||||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
|
||||
CFLAGS += --coverage
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
void blink_dummy_func(void)
|
||||
{
|
||||
static int i;
|
||||
printf("blink_dummy_func: Counter = %d\n", i++);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/* Blink Example with covergae info
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_app_trace.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
/* Can use project configuration menu (idf.py menuconfig) to choose the GPIO
|
||||
to blink, or you can edit the following line and set a number here.
|
||||
*/
|
||||
#define BLINK_GPIO CONFIG_BLINK_GPIO
|
||||
|
||||
void blink_dummy_func(void);
|
||||
void some_dummy_func(void);
|
||||
|
||||
static void blink_task(void *pvParameter)
|
||||
{
|
||||
// The first two iterations GCOV data are dumped using call to esp_gcov_dump() and OOCD's "esp32 gcov dump" command.
|
||||
// After that they can be dumped using OOCD's "esp32 gcov" command only.
|
||||
int dump_gcov_after = -2;
|
||||
/* Configure the IOMUX register for pad BLINK_GPIO (some pads are
|
||||
muxed to GPIO on reset already, but some default to other
|
||||
functions and need to be switched to GPIO. Consult the
|
||||
Technical Reference for a list of pads and their default
|
||||
functions.)
|
||||
*/
|
||||
gpio_pad_select_gpio(BLINK_GPIO);
|
||||
/* Set the GPIO as a push/pull output */
|
||||
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
|
||||
|
||||
while(1) {
|
||||
/* Blink off (output low) */
|
||||
gpio_set_level(BLINK_GPIO, 0);
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
/* Blink on (output high) */
|
||||
gpio_set_level(BLINK_GPIO, 1);
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
blink_dummy_func();
|
||||
some_dummy_func();
|
||||
if (dump_gcov_after++ < 0) {
|
||||
// Dump gcov data
|
||||
printf("Ready to dump GCOV data...\n");
|
||||
esp_gcov_dump();
|
||||
printf("GCOV data have been dumped.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
xTaskCreate(&blink_task, "blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
CONFIG_FREERTOS_UNICORE=y
|
||||
@@ -0,0 +1,8 @@
|
||||
CONFIG_APPTRACE_DEST_TRAX=y
|
||||
# CONFIG_APPTRACE_DEST_NONE is not set
|
||||
CONFIG_APPTRACE_ENABLE=y
|
||||
CONFIG_APPTRACE_LOCK_ENABLE=y
|
||||
CONFIG_APPTRACE_ONPANIC_HOST_FLUSH_TMO=-1
|
||||
CONFIG_APPTRACE_POSTMORTEM_FLUSH_THRESH=0
|
||||
CONFIG_APPTRACE_PENDING_DATA_SIZE_MAX=0
|
||||
CONFIG_APPTRACE_GCOV_ENABLE=y
|
||||
Reference in New Issue
Block a user