Retargeting getchar() function
Hi,
I’m trying to retarget the getchar() function.
My simple goal is, for the moment, to wait until the ‘p’ key is pressed on the PC console.
-----------------------------------
Hereafter the working code:
> // Wait for ‘p’ char pressed
> HAL_UART_Receive (&huart3, (uint8_t *)&c, 1, 0xFFFF);
> while (c != ‘p’) {
> HAL_UART_Receive (&huart3, (uint8_t *)&c, 1, 0xFFFF);
> }
-----------------------------------
Instead, if I use the following code, the program stucks into the GETCHAR_PROTOTYPE routine:
> #ifdef GNUC
> /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
> set to ‘Yes’) calls __io_putchar() */
> #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
> #define GETCHAR_PROTOTYPE int __io_getchar(void)
> #else
> #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
> #define GETCHAR_PROTOTYPE int fgetc(FILE *f)
> #endif /* GNUC */
...
> GETCHAR_PROTOTYPE {
> int ch;
> HAL_UART_Receive (&huart3, (uint8_t *)&ch, 1, 0xFFFF);
> return ch;
> }
...
> // Wait for ‘p’ char pressed
> c = getchar();
> while (c != ‘p’) {
> c = getchar();
> }
In particular, the char is correctly captured by HAL_UART_Receive (I can see the char by using the breackpoints), but the GETCHAR_PROTOTYPE repeats infinitely without exiting and the while loop is never reached.
What is wrong with the code?
Thanks in advance!
Flavio