Menu

#153 Error running stm32flash with QProcess (qt)

none
New
nobody
None
Medium
Defect
2023-02-20
2023-02-06
No

Hi, i'm trying to run stm32flash with qt process, but it gives "device not specified" error.
but running the same command on terminal, it works.
i'm using version 0.7.

QProcess *loadFirmware = new QProcess();
loadFirmware->start("stm32flash", QStringList() << "-b 9600 -w /run/media/sdb1/LandingBuilds/bool_cnt/Control.bin /dev/ttyUSB0");
loadFirmware->waitForFinished(-1);
qDebug() << loadFirmware->readAllStandardError();
qDebug() << loadFirmware->readAllStandardOutput();

Discussion

1 2 > >> (Page 1 of 2)
  • Tormod Volden

    Tormod Volden - 2023-02-06

    Obviously this has nothing to do with stm32flash since it works on the command line.

    You must read the QProcess() and QStringList() documentation. It looks like you are giving the arguments as one big string instead of a list of strings.

     
  • Enrico Razzaboni

    are you sure that has nothing to do with stm32flash? because all other process works...

     
    • Tormod Volden

      Tormod Volden - 2023-02-06

      Yes. Do these "other process" have a list of arguments? Simply fix your ->start invocation.

       
  • Enrico Razzaboni

    yes, one example:

    gpio5.start("bash", QStringList() << "-c" << "echo 1 > /sys/class/gpio/gpio5/value");
    
     
  • Tormod Volden

    Tormod Volden - 2023-02-06

    Exactly, you are using << to append elements to the list of strings, and not passing one large string. Do you understand the difference between a list of strings and a string?

    See for example https://doc.qt.io/qt-6/qstringlist.html#adding-strings to understand what you are doing.

     
  • Enrico Razzaboni

    yes i've understood it. but id doesn't change.

     
    • Tormod Volden

      Tormod Volden - 2023-02-06

      Well, show me what you tried, so that I can tell you what you did wrong.

       
      • Enrico Razzaboni

        ok i've tried this morning with this syntax and something change. but i've another error.
        code:

        QProcess *loadFirmware = new QProcess();
        loadFirmware->start("stm32flash", QStringList() << "-b" << "9600" << "-w" << path << " /dev/ttyUSB0");
        loadFirmware->waitForFinished(-1);
        qDebug() << loadFirmware->readAllStandardError();
        qDebug() << loadFirmware->readAllStandardOutput();
        

        output:

        "Error probing interface \"serial_posix\"\nCannot handle device \" /dev/ttyUSB0\"\nFailed to open port:  /dev/ttyUSB0\n"
        "stm32flash 0.7\n\nhttp://stm32flash.sourceforge.net/\n\nUsing Parser : Raw BINARY\nSize         : 301172\n\n"
        
         
        • Tormod Volden

          Tormod Volden - 2023-02-07

          Here there was an extra space in front of the file name. Remember that these strings are passed directly to the program (which will find them in argv) and no shell is involved to "tidy up" whitespace.

           
      • Enrico Razzaboni

        edit: there was an error on my code.

        QProcess *loadFirmware = new QProcess();
        loadFirmware->start("stm32flash", QStringList() << "-b" << "9600" << "-w" << path << "/dev/ttyUSB0");
        loadFirmware->waitForFinished(-1);
        qDebug() << loadFirmware->readAllStandardError();
        qDebug() << loadFirmware->readAllStandardOutput();
        

        output:

        "Failed to init device after retry.\n"
        "stm32flash 0.7\n\nhttp://stm32flash.sourceforge.net/\n\nUsing Parser : Raw BINARY\nSize         : 301172\nInterface serial_posix: 9600 8E1\n\n"
        

        why i've "failed to init after retry?", if i run it on terminal, it works.

         
        • Tormod Volden

          Tormod Volden - 2023-02-07

          Is is possible that your program calls stm32flash twice? Or writes to the serial port?

           
          • Enrico Razzaboni

            no it's impossible :(

             
          • Enrico Razzaboni

            i've looked at the serial communication with serial sniffer. this is the result

             
            • Tormod Volden

              Tormod Volden - 2023-02-08

              Looks strange, but also that the baud rate is 56000 and that there are two ports, COM4 and COM5. And this looks like Windows. I don't think you have mentioned anything about this running in a virtual machine or so.

               
              • Enrico Razzaboni

                stm32flash is running on embedded device with Yocto.
                you see windows screen because I've created a serial sniffer to watch what's going on.
                i attach a photo to undestand better

                 
                • Tormod Volden

                  Tormod Volden - 2023-02-08

                  That is good to know. From the timestamps it looks like the device is answering very slowly, after one second. But maybe we cannot trust the timestamps so much because it shows the time that the sniffer program detected it and not exactly what time it was on the wire. Maybe you can try something like https://github.com/geoffmeyers/interceptty on Yocto.

                  Anyway, I am curious enough that I would like to reproduce this. Can you please attach a minimal (console) program source that uses this QProcess call?

                   
                  • Enrico Razzaboni

                    ok, what you need?

                     
                    • Tormod Volden

                      Tormod Volden - 2023-02-08

                      A minimal (console) program source that uses this QProcess call.

                       
                      • Tormod Volden

                        Tormod Volden - 2023-02-08

                        I guess it is basically the code snippet you posted above, but with needed #includes and main() etc.

                         
                        • Enrico Razzaboni

                          ok, here it is

                           
                          👍
                          1
  • Enrico Razzaboni

    but if you're sure that it not depends on your software, i'll find another solution

     
  • Tormod Volden

    Tormod Volden - 2023-02-08

    Thanks. I simplified it a bit, I think the QApplication is not necessary here and only makes it stuck in its event loop. The code snippet basically only needed adding the #includes, of which I almost could have guessed the name :) I will test it later.

    #include <QProcess>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {
        QProcess *loadFirmware = new QProcess();
        loadFirmware->start("stm32flash", QStringList() << "-w" << argv[1] << "/dev/ttyUSB0");
        loadFirmware->waitForFinished(-1);
        qDebug() << loadFirmware->readAllStandardOutput();
        qDebug() << loadFirmware->readAllStandardError();
    
        return 0;
    }
    

    And I compile it with:

    g++ `pkg-config --cflags Qt5Core` -fPIC -o testqprocess main.cpp `pkg-config --libs Qt5Core`
    

    EDIT: It worked fine (with PL2303HX USB UART and STM32F103).

     
    👍
    1

    Last edit: Tormod Volden 2023-02-08
  • Tormod Volden

    Tormod Volden - 2023-02-09

    Can you please verify that you still have the same issue with this minimal QProcess test program?

     
  • Enrico Razzaboni

    yes, i've the same issue

     
  • Enrico Razzaboni

    Hi, i've tried also to run stm32 from bash file, and run bash file from qt.
    but i've the same result.
    bash code:

    #!/bin/bash
    
    PATH_GPIO_EXP="/sys/class/gpio/export"
    PATH_GPIO_DIR="/sys/class/gpio"
    
    RESET="5"
    C_BOOT="4"
    P_BOOT="3"
    
    sudo echo 0 > $PATH_GPIO_DIR/gpio$RESET/value
    sudo echo 1 > $PATH_GPIO_DIR/gpio$C_BOOT/value
    sudo echo 0 > $PATH_GPIO_DIR/gpio$P_BOOT/value
    
    /bin/sleep 4
    
    sudo echo 1 > $PATH_GPIO_DIR/gpio$RESET/value
    sudo stm32flash -w $1 /dev/ttyUSB0
    
     
1 2 > >> (Page 1 of 2)

Anonymous
Anonymous

Add attachments
Cancel