Skip to content

Commit 0c5454e

Browse files
authored
HardwareSerial: use correct UART HW for TX #180
openwch/arduino_core_ch32#180
1 parent fa62d6d commit 0c5454e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

cores/arduino/ch32/uart.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,40 @@ int uart_getc(serial_t *obj, unsigned char *c)
523523
return -1;
524524
}
525525

526+
if (!USART_GetFlagStatus(uart_handlers[obj->index]->Instance, USART_FLAG_RXNE)){
527+
return -1;
528+
}
526529
*c = (unsigned char)USART_ReceiveData(uart_handlers[obj->index]->Instance);
527530

528531
return 0;
529532
}
530533

531534

535+
/**
536+
* @brief Write byte to uart
537+
* @param obj : pointer to serial_t structure
538+
* @retval error status
539+
*/
540+
int uart_putc(serial_t *obj, unsigned char c)
541+
{
542+
uint32_t tickstart = GetTick();
543+
544+
if (obj == NULL) {
545+
return -1;
546+
}
547+
548+
while (serial_tx_active(obj))
549+
{
550+
if ((GetTick() - tickstart) >= TX_TIMEOUT)
551+
{
552+
return 0;
553+
}
554+
}
555+
556+
USART_SendData(uart_handlers[obj->index]->Instance, c);
532557

558+
return 0;
559+
}
533560

534561

535562

0 commit comments

Comments
 (0)