platformio / platform-ststm32

ST STM32: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/ststm32
Apache License 2.0
388 stars 305 forks source link

Portenta H7: broken pipe (uploading with dfu) #694

Open sigurd4 opened 1 year ago

sigurd4 commented 1 year ago

I've setup a Platform.io workspace for use with Arduino Portenta H7 in VSCode. I am running Ubuntu-20.04 on WSL2 for Windows 10 using usbip for attaching the usb-port to WSL.

Compilation works fine.

When i upload i get the following:

Processing portenta_h7 (platform: ststm32; board: portenta_h7_m7; framework: arduino)
--------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/portenta_h7_m7.html
PLATFORM: ST STM32 (15.6.0) > Arduino Portenta H7 (M7 core)
HARDWARE: STM32H747XIH6 480MHz, 511.35KB RAM, 768KB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, stlink)
PACKAGES: 
 - framework-arduino-mbed @ 4.0.2 
 - tool-dfuutil @ 1.11.0 
 - tool-openocd @ 2.1100.211028 (11.0) 
 - tool-stm32duino @ 1.0.1 
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 42 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/portenta_h7/src/main.cpp.o
Linking .pio/build/portenta_h7/firmware.elf
Checking size .pio/build/portenta_h7/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  11.7% (used 61040 bytes from 523624 bytes)
Flash: [==        ]  17.1% (used 134704 bytes from 786432 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, dfu, jlink, mbed, stlink
CURRENT: upload_protocol = dfu
Looking for upload port...
Using manually specified: /dev/ttyACM0
*** [upload] Broken pipe
===== [FAILED] Took 7.24 seconds =====

Environment    Status    Duration
-------------  --------  ------------
portenta_h7    FAILED    00:00:07.240
 1 failed, 0 succeeded in 00:00:07.240

This is my platformio.ini file:

[platformio]
default_envs = portenta_h7

[env:portenta_h7]
platform = ststm32
board = portenta_h7_m7
upload_protocol = dfu
framework = arduino
build_src_filter = +<*>

If i upload using Arduino IDE it works, both from Windows and WSL2 Ubuntu. I have updated the bootloader of the microcontroller by following these steps: https://support.arduino.cc/hc/en-us/articles/4404067649554-Update-the-bootloader-on-Portenta-H7-boards. When uploading it's set to bootloader-mode, with the green LED blinking.

This deleted post on stackoverflow appears to describe the same problem: https://web.archive.org/web/20220602165523/https://stackoverflow.com/questions/72362799/broken-pipe-error-when-uploading-to-arduino-portenta-h7-with-platformio-on-lin

My code (single file main.cpp):

#include <Arduino.h>

void setup()
{

}

void loop()
{

}

Running ´pio run --target upload --environment portenta_h7 --upload-port /dev/ttyACM0 --verbose´ in PlatformIO CLI

Processing portenta_h7 (platform: ststm32; board: portenta_h7_m7; upload_protocol: dfu; framework: arduino; build_src_filter: +<*>; lib_deps: ; lib_ignore: ros_lib)
--------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/portenta_h7_m7.html
PLATFORM: ST STM32 (15.6.0) > Arduino Portenta H7 (M7 core)
HARDWARE: STM32H747XIH6 480MHz, 511.35KB RAM, 768KB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, stlink)
PACKAGES: 
 - framework-arduino-mbed @ 4.0.2 
 - tool-dfuutil @ 1.11.0 
 - tool-openocd @ 2.1100.211028 (11.0) 
 - tool-stm32duino @ 1.0.1 
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Ignored library /home/sigurd/ws_arduino/LoneWolf2023GearingArduino/lib/ros_lib
More details about "Library Compatibility Mode": https://docs.platformio.org/page/librarymanager/ldf.html#ldf-compat-mode
Found 42 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
MethodWrapper(["checkprogsize"], [".pio/build/portenta_h7/firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  11.7% (used 61040 bytes from 523624 bytes)
Flash: [==        ]  17.1% (used 134704 bytes from 786432 bytes)
.pio/build/portenta_h7/firmware.elf  :
section               size        addr
.text               129392   134479872
.ARM.extab             588   134609264
.ARM.exidx            1136   134609852
.data                 4176   603979776
.uninitialized          16   603983952
.bss                 56864   603983968
.openamp_section         0   939524096
.pdm_section         64512   939524096
.heap               462208   604040832
.lwip_sec           278528   805306368
.ARM.attributes         44           0
.comment               156           0
.debug_frame          7100           0
.stab                   60           0
.stabstr               118           0
Total              1004898
<lambda>(["upload"], [".pio/build/portenta_h7/firmware.bin"])
AVAILABLE: cmsis-dap, dfu, jlink, mbed, stlink
CURRENT: upload_protocol = dfu
BeforeUpload(["upload"], [".pio/build/portenta_h7/firmware.bin"])
Using manually specified: /dev/ttyACM0
*** [upload] Broken pipe
=================================== [FAILED] Took 1.61 seconds ===================================

Environment    Status    Duration
-------------  --------  ------------
arduino_uno    IGNORED
portenta_h7    FAILED    00:00:01.605
============================= 1 failed, 0 succeeded in 00:00:01.605 =============================

How come this doesn't work?

MarcelRobitaille commented 1 year ago

@sigurd4 I'm also getting this. Did you find a solution?

sigurd4 commented 1 year ago

@MarcelRobitaille No. A temporary (non-ideal) solution is to lint and write the code in VSCode, and flash the device with Arduino IDE. If you use the newest version of Arduino IDE it's possible to make your workspace compatible with both IDE's, by adding an .ino file in the project folder with #include "main.hpp" and add a header file for main.cpp with setup and loop functions visible.

MarcelRobitaille commented 1 year ago

I've had success pressing the reset button a single time before flashing instead of 2.

maxgerhardt commented 1 year ago
Using manually specified: /dev/ttyACM0

Weird -- wouldn't DFU use a USB device, not a serial port? What happens when you delete the upload_port = .. section of your platformio.ini?

MarcelRobitaille commented 1 year ago

I don't have any upload_port in my platformio.ini and I'm still getting this.

Configuring upload protocol...
AVAILABLE: cmsis-dap, dfu, jlink, mbed, stlink
CURRENT: upload_protocol = dfu
Looking for upload port...
Auto-detected: /dev/ttyACM0
maxgerhardt commented 1 year ago

Ah yes, it tries to find a serial port so that it can reset the board into bootloader mode using a 1200 baud open serial port procedure.

https://github.com/platformio/platform-ststm32/blob/9da8f1bafcfd8b2a59061962dc1e298f545b52a4/boards/portenta_h7_m7.json#L44-L46

Do you get any new messages on sudo dmesg after after the broken pipe error?

sigurd4 commented 1 year ago

@maxgerhardt I no longer have access to the Portenta H7 in question, because the project i was on is now over. Good luck

mathemaphysics commented 1 month ago

Same thing here. One day I double click into blinking green light bootloader mode and flash and it gives broken pipe. Had to flash it in the Arduino IDE after the SOS went off.