__io_getchar implementation for getchar() has a problem
Please forgive me for bothering you yet again but I seem to have run into another issue.
I am attempting to implement getchar() and putchar() using io_getchar() and io_putchar() and I am running into a strange issue.
When I make a call to getchar() it calls srget_r() who calls srefill_r() who calls __sread() who calls _read_r() who calls _read().
The problem is that the _read function (in syscalls.c) is getting called with a length of 1024. Since the initial call was to getchar() a single character should have been requested.
This is causing my program to both crash and/or lock up due to over running my 1 byte buffer.
Am I missing something in my implementation of io_getchar? I have included the _read function from syscalls.c (found in the STM32Cube examples directory) and my io_getchar function.
Prior to implementing __io_getchar() I made sure that HAL_UART_Receive_DMA() is working properly.
In the mean time I am modifying _read to ignore the len parameter and only read a single byte.
int _read (int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
*ptr++ = __io_getchar();
}
return len;
}
int __io_getchar( void )
{
uint8_t Byte;
HAL_UART_Receive_DMA( &huart6, &Byte, 1 );
RxReady = FALSE;
while ( !RxReady );
return (int)Byte;
}