Skip to content

Latest commit

 

History

History
75 lines (58 loc) · 2.67 KB

File metadata and controls

75 lines (58 loc) · 2.67 KB

STM32F746G-DISCO USB CDC image loopback

This example uses the existing PyDIPLink raw-image protocol over USB CDC. USB CDC appears as a serial device to PySerial, so no new PC driver or a second protocol is required.

The board initiates every transaction when its blue user button is pressed:

F746 button
    |
    +--> STR + width + height + format + depth  --> PC
    |                                             |
    |                                   image resized and encoded
    |                                             |
    +<---------------- raw pixel bytes ----------+
    |
    +--> STW + metadata + same raw pixels -------> PC (saved as PNG)

width, height, format, and depth are unsigned 32-bit little-endian values. STR and STW are three-byte ASCII command tags. This is the protocol already implemented by the pydiplink command.

Connect the correct USB port

Use a data-capable Micro-USB cable from the PC to CN13, USB OTG FS on the target STM32F746 MCU. Do not use the ST-LINK Type-B connector for image data: it is for programming/debugging and its virtual COM port remains useful as the MicroPython REPL.

After connecting CN13, identify the new device:

ls /dev/ttyACM*

Normally the ST-LINK REPL is /dev/ttyACM0 and the native USB CDC device is /dev/ttyACM1, but choose the device shown by your own system. On Linux, add your user to dialout if opening the port gives a permission error, then log out and back in.

Run the example

First install the firmware once, then copy the application using the ST-LINK REPL port. Close any serial console before embeddip put because only one program can own a serial port.

cd /path/to/embeddip-micropython
source .venv/bin/activate
embeddip put examples/usb_cdc_image_loopback.py --main --port /dev/ttyACM0

Reset the board. The application detaches the native USB CDC interface from the MicroPython REPL, so it is a clean binary data channel; console output continues on the ST-LINK UART.

On the PC, install PyDIPLink and start it before pressing the button:

cd /path/to/PyDIPLink
python3 -m venv .venv
.venv/bin/pip install -e .
.venv/bin/pydiplink --port /dev/ttyACM1 --baud 115200 \
  --image /absolute/path/to/input.png --no-queue

--baud is required by the serial API but does not limit USB CDC throughput. Every press requests a 160x120 GRAY8 frame. PyDIPLink resizes the selected image, sends 19,200 bytes to the board, receives the identical frame, and saves it as received_images/image_<timestamp>.png.

Use the ST-LINK port only for embeddip repl and development commands. Do not open the native USB CDC port in a terminal while PyDIPLink owns it.