We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Why doesn't scanf work when used in a task? How can I solve the problem? I use STM32 and the standard retarget with uart. I see that only scanf doesn't work, gets() and printf() for example doesn't make me any problem! Thnks
...so... my retarget function is
fputc(...) { while(!(USART2->SR & USART_SR_RXNE)); return USART2->DR; }
i noticed that scanf call fputc and when the scheduler change the task while fputc is waiting for a character, rtx go in idle task and doesn't return to execute fputc, the task is so blocked. I try to use a retarget function like this
fputc(...) { tsk_lock(); while(!(USART2->SR & USART_SR_RXNE)); tsk_unlock(); return USART2->DR; }
Now scanf can get the characters but evenif i send a 0x0D, the function doesn't return to the task blocking it.
Check you heap size
heap size : 0x00001400
Filippo,
According to this link:
http://www.keil.com/support/man/docs/rlarm/rlarm_tsk_lock.htm
the tsk_lock() function essentially removes the RTX kernel from the equation.
What is the tasks declared stack size? Did you watch the stack memory during the scanf() function call and verify your return address was not out of the tasks stack space?
Ok, increasing task stack size from 0x200 to 0x300 scanf can get the character from getkey()....but still don't return to the task! I have tried to increase stack size to 0x800 but scanf don't return yet!
If you have watched the stack as I suggested and the return address is clearly obvious, then I would guess that the parameters list for your scanf() call are not setup correctly.
http://www.keil.com/support/man/docs/c251/c251_scanf.htm
BTW: I seem to vaguely remember that the scanf() routine does use a 'boatload' of stack space.
Also, you can try to remove the scanf() function call and replace it with something more simplistic for test purposes.
For example, does _getkey() work from your call and return properly?
"replace it with something more simplistic for test purposes."
Actually, it might be worth doing a 'Search' on this forum for "scanf" - and, in the light of what you find, then re-considering whether you really want to be using it at all...
That would be the C251 version - you should be looking at the ARM version...