Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cores/arduino/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,17 @@ int HardwareSerial::read(void)
size_t HardwareSerial::write(const uint8_t *buffer, size_t size)
{

return uart_debug_write((uint8_t *)buffer, size);
for (size_t i = 0; i < size; i++) {
write(buffer[i]);
}

return len;
}


size_t HardwareSerial::write(uint8_t c)
{
uint8_t buff = c;
return write(&buff, 1);
return uart_putc(&_serial, c);
}

void HardwareSerial::setRx(uint32_t _rx)
Expand Down
24 changes: 24 additions & 0 deletions cores/arduino/ch32/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,30 @@ int uart_getc(serial_t *obj, unsigned char *c)
return 0;
}

/**
* @brief Write byte to uart
* @param obj : pointer to serial_t structure
* @retval error status
*/
int uart_putc(serial_t *obj, unsigned char c)
{
uint32_t tickstart = GetTick();

if (obj == NULL) {
return -1;
}

while (serial_tx_active(obj))
{
if ((GetTick() - tickstart) >= TX_TIMEOUT)
{
return 0;
}
}

return USART_SendData(uart_handlers[obj->index]->Instance, c);

}



Expand Down
1 change: 1 addition & 0 deletions cores/arduino/ch32/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ typedef struct __UART_HandleTypeDef
void uart_deinit(serial_t *obj);

int uart_getc(serial_t *obj, unsigned char *c);
int uart_putc(serial_t *obj, unsigned char c);

uint8_t serial_tx_active(serial_t *obj);
uint8_t serial_rx_active(serial_t *obj);
Expand Down