From eefa769bc8accc71860ff8b8289d618deb90ca4e Mon Sep 17 00:00:00 2001 From: rmanach Date: Wed, 5 Mar 2025 15:44:21 +0100 Subject: [PATCH] add usb serial support --- .gitignore | 1 + README.md | 29 +++++++++++++++ buzzer/CMakeLists.txt | 1 + scripts/install_tiny_usb.bash | 67 +++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100755 scripts/install_tiny_usb.bash diff --git a/.gitignore b/.gitignore index 5223671..09f51e4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ picotool sdk freertos* +tinyusb build toolchain diff --git a/README.md b/README.md index 9463670..6f6086d 100644 --- a/README.md +++ b/README.md @@ -90,3 +90,32 @@ Metadata Block 1 image type: ARM Secure ``` +## Show program outputs via USB serial mode +In order to show logs from your program running on the microcontroller, you have to integrate [TinyUSB](https://github.com/raspberrypi/tinyusb/tree/pico) in the Pico C SDK. + +### Installation +To do it, simply launch the following command: +```bash +./scripts/install_tiny_usb.bash +# for the 0.17.0 version +./scripts/install_tiny_usb.bash 0.17.0 +``` + +It will download TinyUSB sources and create a symbolic link in the Pico C SDK for integration at compilation. + +**NOTE**: If the SDK is located in specific directory, set the **INSTALL_PATH** variable pointing to the directory of the SDK before to launch the script. + +### Display output on terminal +Recompile and push your program on the microcontroller. Then to display the program outputs, you have to use `minicom`. + +```bash +sudo apt install minicom +``` + +**NOTE**: if you have the habit to use another tool then, use it ! + +After the installation, the microcontroller plug into the USB port, you can launch the command to visualize the program outputs: + +```bash +sudo minicom -b 115200 -o -D /dev/ttyACM0 +``` diff --git a/buzzer/CMakeLists.txt b/buzzer/CMakeLists.txt index 8415d68..50368d0 100644 --- a/buzzer/CMakeLists.txt +++ b/buzzer/CMakeLists.txt @@ -52,6 +52,7 @@ set(FREERTOS_PORT_FILES add_executable(buzzer main.c log.c gpio.c jobs.c utils.c ${FREERTOS_SOURCES} ${FREERTOS_PORT_FILES}) add_definitions(-DPICO) +add_definitions(-DLOG_LEVEL=INFO) pico_set_program_name(buzzer "buzzer") pico_set_program_version(buzzer "0.1") diff --git a/scripts/install_tiny_usb.bash b/scripts/install_tiny_usb.bash new file mode 100755 index 0000000..63526a5 --- /dev/null +++ b/scripts/install_tiny_usb.bash @@ -0,0 +1,67 @@ +#!/bin/bash + +############################################### +# +# Download and install Tiny USB. +# src: https://github.com/hathach/tinyusb +# +# ex: ./install_tiny_usb.bash 0.17.0 +# +############################################### + +TINY_USB_VERSION=$1 +REGEX_VERSION="^[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}$" + +if [[ -z ${INSTALL_PATH} ]] +then + INSTALL_PATH=${PWD} +fi + +usage() { + echo "usage:" + echo "./install_tiny_usb.bash (ex: ./install_tiny_usb.bash 2.1.0)" +} + +if [[ ! "${TINY_USB_VERSION}" =~ ${REGEX_VERSION} ]] +then + echo "error: unable to parse the version: '${TINY_USB_VERSION}'" + usage + exit 1 +fi + +if [[ ! -d ${INSTALL_PATH}/tinyusb/${TINY_USB_VERSION} ]] +then + echo "installing Tiny USB ${TINY_USB_VERSION}" + + tar_file="${TINY_USB_VERSION}.tar.gz" + wget https://github.com/hathach/tinyusb/archive/refs/tags/${TINY_USB_VERSION}.tar.gz -P ${INSTALL_PATH} + if [[ $? != 0 ]] + then + echo "error: unable to get tiny USB VERSION: ${TINY_USB_VERSION}" + exit 1 + fi + + mkdir -p ${INSTALL_PATH}/tinyusb + tar xzvf ${INSTALL_PATH}/${tar_file} -C ${INSTALL_PATH}/tinyusb + rm ${INSTALL_PATH}/${tar_file} + + mv ${INSTALL_PATH}/tinyusb/tinyusb-${TINY_USB_VERSION} ${INSTALL_PATH}/tinyusb/${TINY_USB_VERSION} + + echo "find Pico SDK to add TinyUSB support on compilation..." + tiny_usb_dir=$(find ${INSTALL_PATH}/sdk -name tinyusb -type d | grep lib | head -1) + if [[ ! -z ${tiny_usb_dir} ]] + then + cd ${tiny_usb_dir}/.. + lib_dir=${PWD} + + rmdir ${tiny_usb_dir} + ln -s ${INSTALL_PATH}/tinyusb/${TINY_USB_VERSION} tinyusb + + echo "Tiny USB soft link added to Pico SDK: $(ls -lrt ${lib_dir}/tinyusb)" + fi + + echo "Tiny USB installed successfully: ${INSTALL_PATH}/tinyusb/${TINY_USB_VERSION}" + exit 0 +fi + +echo "Tiny USB already exists: ${INSTALL_PATH}/tinyusb/${TINY_USB_VERSION}" \ No newline at end of file