scanf/printf not working when calling generated C code

36 vues (au cours des 30 derniers jours)
Victor Lam
Victor Lam le 23 Fév 2026 à 11:36
Modifié(e) : dpb le 23 Fév 2026 à 21:39
In Matlab I have generated C code (.c/.h files) from a Matlab function using codegen from Matlab Coder.
I call this function in a while loop on an ARM quad-core Cortex A53 using AMD Vitis.
Before calling this function I use scanf/printf to get user input and to print to the serial monitor. However, scanf/printf only work once in the 1st iteration (before calling the function) and not in the 2nd iteration or later (after calling the function).
Is this a common problem and has anyone encountered this problem before?
I think, but am not sure, that the problem is in the generated C code and not in Vitis itself.
Thank you in advance!
  3 commentaires
Victor Lam
Victor Lam il y a environ une heure
Let's say the sequence of one iteration is: scanf + printf + function. In the 1st iteration it asks for user input and prints a message, but then the while loop runs forever without ever asking for user input or printing anything again in the 2nd iteration or later.
But if I comment out this function then in every iteration it always asks for user input and prints a message, as one would normally expect.
I used debugger mode to verify that the function has terminated and is not stuck. I also verified for specific inputs that the output of the function in C is identical to the Matlab function.
Does this behaviour occur more often or has anyone seen something like this before?
dpb
dpb il y a environ 10 heures
Modifié(e) : dpb il y a environ 4 heures
Probably no one has ever done precisely the same thing with the combination of environment and hardware so it's extremely likely the answer to that question is "No".
Knowing nothing of what the function does nor anything about the system you're running, it's unlikely anybody here can help.
If not calling the function removes the symptoms, then it is conclusive that something in either the calling/return linkage is broken or the function itself did something damaging outside returning its expected output(s). One next debugging step would be to create an empty null function in its stead and test calling it. If that is successful, then add the argument list alone, then the output arguments until find what step causes something to break. You could also try replacing the function call with something simple like timestwo.c and make sure the code generator can handle the simple case first. It's always possible there is something unique in the development environment it doesn't know about -- maybe a default convention assumed isn't the same as expected.
"... I use scanf/printf to get user input and to print to the serial monitor"
I would suspect that the serial connection got broken would be a fairly likely possibility...
If that doesn't uncover the problem, you'll probably have to submit the whole enchilada to Mathworks suppor.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur MATLAB Coder dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by