Error running stm32flash with QProcess (qt)
Open source flash program for STM32 using the ST serial bootloader
Brought to you by:
tormod
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();
Anonymous
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.
are you sure that has nothing to do with stm32flash? because all other process works...
Yes. Do these "other process" have a list of arguments? Simply fix your ->start invocation.
yes, one example:
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.
yes i've understood it. but id doesn't change.
Well, show me what you tried, so that I can tell you what you did wrong.
ok i've tried this morning with this syntax and something change. but i've another error.
code:
output:
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.
edit: there was an error on my code.
output:
why i've "failed to init after retry?", if i run it on terminal, it works.
Is is possible that your program calls stm32flash twice? Or writes to the serial port?
no it's impossible :(
i've looked at the serial communication with serial sniffer. this is the result
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.
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
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?
ok, what you need?
A minimal (console) program source that uses this QProcess call.
I guess it is basically the code snippet you posted above, but with needed #includes and main() etc.
ok, here it is
but if you're sure that it not depends on your software, i'll find another solution
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.
And I compile it with:
EDIT: It worked fine (with PL2303HX USB UART and STM32F103).
Last edit: Tormod Volden 2023-02-08
Can you please verify that you still have the same issue with this minimal QProcess test program?
yes, i've the same issue
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: