Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

System Workbench for STM32


You are viewing a reply to Retargeting printf  

Retargeting printf

What about retargeting getchar() function?

My simple goal is, for the moment, to wait until the ‘p’ key is pressed on the PC console.
I’m having problem with it...

Infact, I’ve tried to retarget the getchar() function in the same way I’ve done for the printf() function, but without success.

If I use directly the HAL_UART_Receive() function, all is right.
If I try redefining the io_getchar(void), function, I get problems.


---------------

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