Hi,
I use char c = DebugConsole_GetChar(); to read a serial character to simulate operation of a normally keypad driven menu system. I find that if I send two characters repeatedly, the GetChar function starts always returning 0 every call rather than blocking until a character is received.
I traced this through and it appears that in UART_ReadBlocking it checks the UART status (which has a RX buffer overrun flag set) and returns a kStatus_UART_RxHardwareOverrun. Which is ignored by the DbgConsole_Getchar function which happily returns the character 0.
Kind of frustrating. Mainly happens if I pause for debugging and send a character while paused by accident. So hardware is reporting a correct rx buffer overrun but does not seem to be cleared by the debug console code. Sometimes if I step through the code when it is stuck it will clear the flag and come right!
Any ideas???
Hi Ashley Duncan
I confirm that this is a bug in SDK 2.0 driver, I have reported to development team an I will keep you informed for any update that they give me.
A possible workaround is check the return status of UART_ReadBlocking inside the DbgConsole_Getchar function, and return -1 if a error flag is set
int DbgConsole_Getchar(void)
{
char ch;
/* Do nothing if the debug UART is not initialized. */
if (s_debugConsole.type == DEBUG_CONSOLE_DEVICE_TYPE_NONE)
{
return -1;
}
/* Modified */
if( kStatus_Success != (s_debugConsole.ops.rx_union.GetChar(s_debugConsole.base, (uint8_t *)(&ch), 1)))
{
UART_ClearStatusFlags(s_debugConsole.base, kUART_RxOverrunFlag |
kUART_NoiseErrorFlag |
kUART_FramingErrorFlag |
kUART_ParityErrorFlag);
return -1;
}
// s_debugConsole.ops.rx_union.GetChar(s_debugConsole.base, (uint8_t *)(&ch), 1);
return ch;
}
Have a great day,
Jorge Alcala
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
On a side note, the above fix can not quite work as GetChar is defined as:
void (*GetChar)(void *base, const uint8_t *buffer, size_t length);
Might need to be:
/* Modified */
if( kStatus_Success != (s_debugConsole.ops.rx_union.UART_GetChar(s_debugConsole.base, (uint8_t *)(&ch), 1)))
{
Thanks for your help...
FYI see my other topic "How to disable SDK Debug Console" for another possible area requiring improvement. Assuming I have not missed something, you can not compile the SDK without the debug console which is a bit of a nuisance if you want to do your own serial handling.