Skip to content

Commit

Permalink
Merge branch 'fix/zephyr_debug_trace' into 'master'
Browse files Browse the repository at this point in the history
fix: Enable of Zephyr debug trace, add Zephyr CI target test and fix incorrect pinout in README

Closes ESF-162

See merge request espressif/esp-serial-flasher!132
  • Loading branch information
dobairoland committed Jan 3, 2025
2 parents 2a304dc + 7855e5e commit ec8d996
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 4 deletions.
15 changes: 15 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ build_stm32:
build_zephyr:
stage: build
image: espressif/idf:latest
artifacts:
paths:
- "**/build*/zephyr/*.bin"
- "**/build*/zephyr/*.elf"
- "**/build*/zephyr/*.map"
when: always
expire_in: 3 days
tags:
- build
- internet
Expand Down Expand Up @@ -322,6 +329,14 @@ test_esp2:
- pytest --target=esp32 --port=/dev/serial_ports/ESP32_ESP32 -k 'not test_esp32_sdio_load_ram_example'
- pytest --target=esp32s3 --port=/dev/serial_ports/ESP32S3_ESP32C3 -k 'not test_esp32_usb_cdc_acm_example'

test_zephyr:
extends: .test_template
tags:
- ESF-RPI-03
script:
- cd $CI_PROJECT_DIR
- pytest --target=zephyr --port=/dev/serial_ports/ESP32_ESP32

test_stm32:
extends: .test_template
tags:
Expand Down
2 changes: 2 additions & 0 deletions examples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def pytest_configure(config):
pass
elif "pi_pico" in target:
config.option.embedded_services = "serial"
elif "zephyr" in target:
config.option.embedded_services = "serial"
else:
config.option.embedded_services = "esp,idf"

Expand Down
4 changes: 2 additions & 2 deletions examples/zephyr_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Table below shows connection between the two devices:
|:------------:|:----------------------:|
| IO26 | IO0 |
| IO25 | RESET |
| IO4 | TX0 |
| IO5 | RX0 |
| IO4 | RX0 |
| IO5 | TX0 |

## Build and flash

Expand Down
41 changes: 41 additions & 0 deletions examples/zephyr_example/pytest_zephyr_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest
from pytest_embedded import Dut
from esptool.cmds import detect_chip

FLASH_ADDRESS = 0x1000
BIN_FILE = "/zephyr/zephyr.bin"


# This fixture is used to specify the path to the Zephyr app as it is not in the examples directory.
# It is used by conftest.py to find the app path to build directory.
@pytest.fixture
def app_path() -> str:
return "zephyrproject-rtos/zephyr/"


@pytest.fixture(autouse=True)
def flash_zephyr(app_path: str, build_dir: str, port: str) -> None:
with detect_chip(port) as esp:
esp = esp.run_stub()
path = app_path + build_dir + BIN_FILE
with open(path, "rb") as binary:
binary_data = binary.read()
total_size = len(binary_data)

esp.flash_begin(total_size, FLASH_ADDRESS)
for i in range(0, total_size, esp.FLASH_WRITE_SIZE):
block = binary_data[i : i + esp.FLASH_WRITE_SIZE]
# Pad the last block
block = block + bytes([0xFF]) * (esp.FLASH_WRITE_SIZE - len(block))
esp.flash_block(block, i + FLASH_ADDRESS)
esp.flash_finish()
print("Flashed successfully")

esp.hard_reset()


@pytest.mark.zephyr
def test_zephyr_example(dut: Dut) -> None:
for i in range(3):
dut.expect("Finished programming")
dut.expect("Hello world!")
2 changes: 1 addition & 1 deletion private_include/esp_stubs.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2020-2024 Espressif Systems (Shanghai) CO LTD
/* Copyright 2020-2025 Espressif Systems (Shanghai) CO LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ markers =
stm32: support stm32 target
raspberry: support raspberry target
pi_pico: support pi_pico target
zephyr: support zephyr target

# log related
log_cli = True
Expand Down
2 changes: 1 addition & 1 deletion src/esp_stubs.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2020-2024 Espressif Systems (Shanghai) CO LTD
/* Copyright 2020-2025 Espressif Systems (Shanghai) CO LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
4 changes: 4 additions & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ if (CONFIG_ESP_SERIAL_FLASHER)
target_compile_definitions(esp_flasher INTERFACE -DMD5_ENABLED=1)
endif()

if(DEFINED SERIAL_FLASHER_DEBUG_TRACE OR CONFIG_SERIAL_FLASHER_DEBUG_TRACE)
target_compile_definitions(esp_flasher INTERFACE SERIAL_FLASHER_DEBUG_TRACE=1)
endif()

target_compile_definitions(esp_flasher
INTERFACE
SERIAL_FLASHER_WRITE_BLOCK_RETRIES=${CONFIG_SERIAL_FLASHER_WRITE_BLOCK_RETRIES}
Expand Down

0 comments on commit ec8d996

Please sign in to comment.