Skip to content

Commit f504b8f

Browse files
authored
Added uart_putc according PR openwch#180
1 parent 306350f commit f504b8f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

cores/arduino/ch32/uart.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,31 @@ int uart_getc(serial_t *obj, unsigned char *c)
528528
return 0;
529529
}
530530

531+
// PR180: HardwareSerial: use correct UART HW for TX
532+
/**
533+
* @brief Write byte to uart
534+
* @param obj : pointer to serial_t structure
535+
* @retval error status
536+
*/
537+
int uart_putc(serial_t *obj, unsigned char c)
538+
{
539+
uint32_t tickstart = GetTick();
540+
541+
if (obj == NULL) {
542+
return -1;
543+
}
544+
545+
while (serial_tx_active(obj))
546+
{
547+
if ((GetTick() - tickstart) >= TX_TIMEOUT)
548+
{
549+
return 0; // 0 means no error? Should be timeout error?
550+
}
551+
}
552+
553+
USART_SendData(uart_handlers[obj->index]->Instance, c);
554+
return 0; // 0 means no error
555+
}
531556

532557

533558

cores/arduino/ch32/uart.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ typedef struct __UART_HandleTypeDef
9090
void uart_deinit(serial_t *obj);
9191

9292
int uart_getc(serial_t *obj, unsigned char *c);
93+
int uart_putc(serial_t *obj, unsigned char c); // PR180: HardwareSerial: use correct UART HW for TX
9394

9495
uint8_t serial_tx_active(serial_t *obj);
9596
uint8_t serial_rx_active(serial_t *obj);

0 commit comments

Comments
 (0)