YOGYUI

[ESP-IDF] ESP 칩 리셋하지 않고 시리얼 모니터링하기 본문

Hardware/Espressif

[ESP-IDF] ESP 칩 리셋하지 않고 시리얼 모니터링하기

요겨 2023. 11. 29. 12:44
반응형

[ESP-IDF] Monitoring serial without esp chip reset

Notes: ESP-IDF 5.1.1 버전을 대상으로 작성된 글

ESP32 계열 칩셋 펌웨어 개발시 사용하는 SDK인 ESP-IDF

ESP-IDF의 커맨드 라인 인터페이스(CLI) 툴인 idf.py 파이썬 스크립트를 사용해서 프로젝트 설정, 펌웨어 빌드, 플래시, 모니터링 등 다양한 기능을 수행할 수 있다 (특히 상품화 단계에서 필수적인 펌웨어 encryption, component size 측정 등 고급 기능도 사용 가능)

idf.py로 수행할 수 있는 다양한 기능들

 

특히, 펌웨어 플래싱 후 내부 동작을 확인하기 위해 로그 출력을 시리얼 포트 (ESP의 UART0)로 읽어 모니터링하는 기능을 자주 활용하게 되는데, idf.py의 monitor 커맨드가 이를 담당하고 있다

$ idf.py -p {serial_port} monitor

 

문제는, 만약 ESP32의 RST(혹은 EN, 칩의 리셋을 담당) 핀이 USB-to-UART brige IC의 RTS 핀과 연결되어 있을 경우, 이 명령은 항상 ESP32 칩을 리셋하게 된다는 점이다

 

새로운 펌웨어를 플래시하지 않은 이상, 현재 동작중인 칩을 리셋없이 모니터링하고 싶은 경우에 사용할 수 없어 꽤나 문제가 되는데, 이를 해결하기 위한 방법을 살짝쿵 알아봤다

1. 방법

$ python3 ${esp-idf-path}/tools/idf_monitor.py -p ${serial port} --no-reset

바쁜 현대인을 위한 두괄식 전개

결론부터 말하자면 idf.py가 호출하는 파이썬 스크립트 중 하나인 idf_monitor.py를 직접 호출하면 되며, 호출 시 --no-reset 플래그만 위와 같이 붙여주면 된다

 

esp-idf 설치경로의 /tools 디렉터리 내부에는 다양한 유틸리티 스크립트들이 존재한다

$ ls ${esp-idf-path}/tools

 

idf_monitor.py 도 해당 경로에 존재하며, 사용법은 --help 플래그를 붙이면 된다

※ executable인 idf.py와 달리 idf_monitor.py는 python3로 스크립트를 로드해서 사용해야 한다

$ python3 ${esp-idf-path}/tools/idf_monitor.py --help

 

옵션 인자 설명은 다음과 같다

options:
  -h, --help show this help message and exit
  --port PORT, -p PORT Serial port device. If not set, a connected port will be used.
  --no-reset Do not reset the chip on monitor startup
  --disable-address-decoding, -d Don't print lines about decoded addresses from the application ELF file
  --baud BAUD, -b BAUD Serial port baud rate
  --make MAKE, -m MAKE Command to run make
  --encrypted Use encrypted targets while running make
  --toolchain-prefix TOOLCHAIN_PREFIX Triplet prefix to add before cross-toolchain names
  --eol {CR,LF,CRLF} End of line to use when sending to the serial port
  --rom-elf-file ROM_ELF_FILE ELF file of target ROM for address decoding. If not specified, autodetection is attempted based on the IDF_PATH and ESP_ROM_ELF_DIR env vars.
  --print_filter PRINT_FILTER Filtering string
  --decode-coredumps {info,disable} Handling of core dumps found in serial output
  --decode-panic {backtrace,disable} Handling of panic handler info found in serial output
  --target TARGET Target name (used when stack dump decoding is enabled)
  --revision REVISION Revision of the target
  --ws WS WebSocket URL for communicating with IDE tools for debugging purposes
  --timestamps Add timestamp for each line
  --timestamp-format TIMESTAMP_FORMAT Set a strftime()-compatible timestamp format
  --force-color Always colored monitor output, even if output is redirected.

2. DEMO

2.1. 일반 모니터링 커맨드 실행 시 (idf.py monitor)

2.2. no reset 플래그로 모니터링 실행 시 (idf_monitor.py --no-reset)

 

이제 칩을 리셋하지 않고도 내부 로그를 바로 확인할 수 있다!

 

끝~!

 

 

반응형
Comments