Skip to content

Commit d8577ca

Browse files
committed
demo cib integration
1 parent 40cd1a5 commit d8577ca

File tree

15 files changed

+1616
-0
lines changed

15 files changed

+1616
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: ESP-IDF Build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Install python dependencies
20+
run: |
21+
pip install -r scripts/requirements.txt
22+
23+
- name: West workspace setup
24+
run: |
25+
west init -l .
26+
west update
27+
28+
- name: Set up Docker (required by esp-idf-ci-action)
29+
uses: docker/setup-buildx-action@v2
30+
31+
- name: esp-idf build
32+
uses: espressif/esp-idf-ci-action@v1
33+
with:
34+
esp_idf_version: v5.5.1
35+
target: esp32
36+
path: 'hello-world'
37+
38+
- name: Upload build artifacts
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: esp-idf-build
42+
path: hello-world/build/hello-world.elf

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build/
2+
.vscode/
3+
.DS_Store
4+
Thumbs.db
5+
ehthumbs.db
6+
Desktop.ini
7+
*~
8+
sdkconfig

CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# west workspace path
2+
set(WORKSPACE_DIR "${CMAKE_CURRENT_LIST_DIR}")
3+
4+
# libraries fetched by https://github.com/cpm-cmake/CPM.cmake are moved here
5+
set(CPM_SOURCE_CACHE "${WORKSPACE_DIR}/cpm")
6+
7+
include(FetchContent)
8+
function(fetch_from_workspace name)
9+
set(options)
10+
set(oneValueArgs SOURCE_DIR)
11+
set(multiValueArgs)
12+
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
13+
14+
if(NOT ARG_SOURCE_DIR)
15+
set(ARG_SOURCE_DIR "${WORKSPACE_DIR}/${name}")
16+
endif()
17+
18+
FetchContent_Declare(
19+
${name}
20+
SOURCE_DIR ${ARG_SOURCE_DIR}
21+
)
22+
FetchContent_MakeAvailable(${name})
23+
endfunction()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ARG DOCKER_TAG=latest
2+
FROM espressif/idf:${DOCKER_TAG}
3+
4+
ENV LC_ALL=C.UTF-8
5+
ENV LANG=C.UTF-8
6+
7+
RUN apt-get update -y && apt-get install udev -y
8+
9+
RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc
10+
11+
ENTRYPOINT [ "/opt/esp/entrypoint.sh" ]
12+
13+
CMD ["/bin/bash", "-c"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "ESP-IDF QEMU",
3+
"build": {
4+
"dockerfile": "Dockerfile"
5+
},
6+
"customizations": {
7+
"vscode": {
8+
"settings": {
9+
"terminal.integrated.defaultProfile.linux": "bash",
10+
"idf.espIdfPath": "/opt/esp/idf",
11+
"idf.toolsPath": "/opt/esp",
12+
"idf.gitPath": "/usr/bin/git"
13+
},
14+
"extensions": [
15+
"espressif.esp-idf-extension",
16+
"espressif.esp-idf-web"
17+
]
18+
}
19+
},
20+
"runArgs": ["--privileged"]
21+
}

hello-world/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.21)
4+
5+
include(../CMakeLists.txt)
6+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
7+
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
8+
idf_build_set_property(MINIMAL_BUILD ON)
9+
project(hello-world)
10+
11+
fetch_from_workspace(cib)

hello-world/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H21 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | Linux |
2+
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | --------- | -------- | -------- | -------- | -------- | ----- |
3+
4+
# Hello World Example
5+
6+
Starts a FreeRTOS task to print "Hello World".
7+
8+
(See the README.md file in the upper level 'examples' directory for more information about examples.)
9+
10+
## How to use example
11+
12+
Follow detailed instructions provided specifically for this example.
13+
14+
Select the instructions depending on Espressif chip installed on your development board:
15+
16+
- [ESP32 Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/stable/get-started/index.html)
17+
- [ESP32-S2 Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/get-started/index.html)
18+
19+
20+
## Example folder contents
21+
22+
The project **hello_world** contains one source file in C language [hello_world_main.c](main/hello_world_main.c). The file is located in folder [main](main).
23+
24+
ESP-IDF projects are built using CMake. The project build configuration is contained in `CMakeLists.txt` files that provide set of directives and instructions describing the project's source files and targets (executable, library, or both).
25+
26+
Below is short explanation of remaining files in the project folder.
27+
28+
```
29+
├── CMakeLists.txt
30+
├── pytest_hello_world.py Python script used for automated testing
31+
├── main
32+
│ ├── CMakeLists.txt
33+
│ └── hello_world_main.c
34+
└── README.md This is the file you are currently reading
35+
```
36+
37+
For more information on structure and contents of ESP-IDF projects, please refer to Section [Build System](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html) of the ESP-IDF Programming Guide.
38+
39+
## Troubleshooting
40+
41+
* Program upload failure
42+
43+
* Hardware connection is not correct: run `idf.py -p PORT monitor`, and reboot your board to see if there are any output logs.
44+
* The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again.
45+
46+
## Technical support and feedback
47+
48+
Please use the following feedback channels:
49+
50+
* For technical queries, go to the [esp32.com](https://esp32.com/) forum
51+
* For a feature request or bug report, create a [GitHub issue](https://github.com/espressif/esp-idf/issues)
52+
53+
We will get back to you as soon as possible.

hello-world/main/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
idf_component_register(SRCS "hello_world_main.cpp"
2+
PRIV_REQUIRES spi_flash
3+
INCLUDE_DIRS "")
4+
5+
target_link_libraries(${COMPONENT_LIB} # __idf_main
6+
PUBLIC
7+
cib
8+
)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: CC0-1.0
5+
*/
6+
7+
#include <stdio.h>
8+
#include <inttypes.h>
9+
#include "sdkconfig.h"
10+
#include "freertos/FreeRTOS.h"
11+
#include "freertos/task.h"
12+
#include "esp_chip_info.h"
13+
#include "esp_flash.h"
14+
#include "esp_system.h"
15+
16+
void app_main(void)
17+
{
18+
printf("Hello world!\n");
19+
20+
/* Print chip information */
21+
esp_chip_info_t chip_info;
22+
uint32_t flash_size;
23+
esp_chip_info(&chip_info);
24+
printf("This is %s chip with %d CPU core(s), %s%s%s%s, ",
25+
CONFIG_IDF_TARGET,
26+
chip_info.cores,
27+
(chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "",
28+
(chip_info.features & CHIP_FEATURE_BT) ? "BT" : "",
29+
(chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
30+
(chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : "");
31+
32+
unsigned major_rev = chip_info.revision / 100;
33+
unsigned minor_rev = chip_info.revision % 100;
34+
printf("silicon revision v%d.%d, ", major_rev, minor_rev);
35+
if(esp_flash_get_size(NULL, &flash_size) != ESP_OK) {
36+
printf("Get flash size failed");
37+
return;
38+
}
39+
40+
printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024),
41+
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
42+
43+
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
44+
45+
for (int i = 10; i >= 0; i--) {
46+
printf("Restarting in %d seconds...\n", i);
47+
vTaskDelay(1000 / portTICK_PERIOD_MS);
48+
}
49+
printf("Restarting now.\n");
50+
fflush(stdout);
51+
esp_restart();
52+
}

hello-world/pytest_hello_world.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: CC0-1.0
3+
import hashlib
4+
import logging
5+
from typing import Callable
6+
7+
import pytest
8+
from pytest_embedded_idf.dut import IdfDut
9+
from pytest_embedded_idf.utils import idf_parametrize
10+
from pytest_embedded_qemu.app import QemuApp
11+
from pytest_embedded_qemu.dut import QemuDut
12+
13+
14+
@pytest.mark.generic
15+
@idf_parametrize('target', ['supported_targets', 'preview_targets'], indirect=['target'])
16+
def test_hello_world(dut: IdfDut, log_minimum_free_heap_size: Callable[..., None]) -> None:
17+
dut.expect('Hello world!')
18+
log_minimum_free_heap_size()
19+
20+
21+
@pytest.mark.host_test
22+
@idf_parametrize('target', ['linux'], indirect=['target'])
23+
def test_hello_world_linux(dut: IdfDut) -> None:
24+
dut.expect('Hello world!')
25+
26+
27+
@pytest.mark.host_test
28+
@pytest.mark.macos_shell
29+
@idf_parametrize('target', ['linux'], indirect=['target'])
30+
def test_hello_world_macos(dut: IdfDut) -> None:
31+
dut.expect('Hello world!')
32+
33+
34+
def verify_elf_sha256_embedding(app: QemuApp, sha256_reported: str) -> None:
35+
sha256 = hashlib.sha256()
36+
with open(app.elf_file, 'rb') as f:
37+
sha256.update(f.read())
38+
sha256_expected = sha256.hexdigest()
39+
40+
logging.info(f'ELF file SHA256: {sha256_expected}')
41+
logging.info(f'ELF file SHA256 (reported by the app): {sha256_reported}')
42+
43+
# the app reports only the first several hex characters of the SHA256, check that they match
44+
if not sha256_expected.startswith(sha256_reported):
45+
raise ValueError('ELF file SHA256 mismatch')
46+
47+
48+
@pytest.mark.host_test
49+
@pytest.mark.qemu
50+
@idf_parametrize('target', ['esp32', 'esp32c3'], indirect=['target'])
51+
def test_hello_world_host(app: QemuApp, dut: QemuDut) -> None:
52+
sha256_reported = dut.expect(r'ELF file SHA256:\s+([a-f0-9]+)').group(1).decode('utf-8')
53+
verify_elf_sha256_embedding(app, sha256_reported)
54+
55+
dut.expect('Hello world!')

0 commit comments

Comments
 (0)