This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

scanf with rtx

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

Parents
  • ...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.

Reply
  • ...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.

Children